0

I tried this code But does not download File

 while ($row = $result->fetch_assoc()) {
                    $filename=$row['name'];
                echo "<tr>";
                echo "<td>".$i."</td>";
                echo "<td>".$row ['cdetail']. "</td>";
                echo "<td>".$row ['tenNo']. "</td>";
                echo "<td>".$row ['tdetail']. "</td>";
                echo "<td>".$row['ldate']."</td>";
                echo "<td> <a href=adminfrm.php?file=".$filename."target='_blank'>Download</a></td>";

Please, guide me

4
Contributors
22
Replies
95
Views
9 Months
Discussion Span
Last Post by zebnoon1
Featured Replies
  • 1

    If you echo all your variables `($id,$name,$type,$size,$data)` what do you see? Read More

  • 1

    No, echo the variables instead of trying to download the file, so you can see if they contain the correct values. Read More

  • 1

    So, what does it output? Read More

  • 1
    cereal 1,419   9 Months Ago

    **@zebnoon1** Hi, you were asked multiple times, to reply to some questions with useful information. Calmly read again Pritaeas posts and reply to his requests. For example, he asked: > What size is the downloaded file? So the downloaded .pdf file is 0 bytes, few bytes and when opens is … Read More

  • 1

    @cereal: I was typing something similar... ;) Read More

0

adminfrm.php is a my php page. where all data lies.
1-I uploaded PDF files in Dababase

Database: Columbes are

id(int),edate(VARCHAR),ldate(VARCHAR),cdate(VARCHAR),tenNo(VARCHAR),tdetail(VARCHAR),edate(VARCHAR),filename(VARCHAR),filetype(VARCHAR),filesize(bigint),filedata(longbolb)
2.here is code of adminfrm.php

while ($row = $result->fetch_assoc()) {
                echo "<tr>";
                echo "<td>".$i."</td>";
                echo "<td>".$row ['cdetail']. "</td>";
                echo "<td>".$row ['tenNo']. "</td>";
                echo "<td>".$row ['tdetail']. "</td>";
                echo "<td>".$row['ldate']."</td>";
                echo "<td> <a href='download.php'>Download </a></td>";
                echo "<td>".$r."</td>";
}

and here is code of downlod.php

<?php
    include("conn1.php");
    $query="SELECT * FROM ten";
    $result=$conn1->query($query);
       list($id,$name,$type,$size,$data) = mysqli_fetch_assoc($result);

    header("Content-Disposition: attachment; filename=$name");
    header("Content-type: $type/pdf");
    header("Content-length: $size");

    ob_clean();
    flush();
    echo $data;
    //mysqli_close($connection);
    exit;
?>

It does not download PDF in my database.?

Edited by zebnoon1

0

I sent you screen short
It does nothing if i put all variables

<?php
    include("conn1.php");
    $query="SELECT * FROM ten";
    $result=$conn1->query($query);
       list($id,$edate,$cdate,$ldate,$tenNo,$tdetail,$filename,$filemime,$filesize,$filedata) = mysqli_fetch_assoc($result);
    header("Content-Disposition: attachment; filename=$name");
    header("Content-type: $type/pdf");
    header("Content-length: $size");
    ob_clean();
    flush();
    echo $data;
    //mysqli_close($connection);
    exit;
?>

:( what to do sir?

Attachments error.jpg 35.44 KB
1

No, echo the variables instead of trying to download the file, so you can see if they contain the correct values.

-1

no i tried please, check code

include("conn1.php");
    $query="SELECT * FROM tentb";
    $result=$conn1->query($query);
       list($id,$edate,$cdate,$ldate,$tenNo,$tdetail,$filename,$filemime,$filesize,$filedata) = $result->fetch_assoc();
    echo $id;
    //header("Content-Disposition: attachment; filename=$name");
    //header("Content-type: $type/pdf");
    //header("Content-length: $size");
    //ob_clean();
    //flush();
    echo $filedata;
    //mysqli_close($connection);
    exit;

Undefined offset: 9 in C:\wamp\www\SprintWeb\download.php on line 5

please check

0

ok sir sorry for unpatience
here is code change $filename

<?php
    include("conn1.php");
    $query="SELECT * FROM tentb";
    $result=$conn1->query($query);
    list($id,$edate,$cdate,$ldate,$tenNo,$tdetail,$filename,$filemime,
    $filesize,$filedata) = $result->fetch_assoc();
    header('Content-Disposition: attachment;filename=$filename');
    header('Content-type: $filemime/pdf');
    header('Content-length: $filesize');
    ob_clean();
    flush();
    echo $filename;
    //mysqli_close($connection);
    exit;
?>

error is
Notice: Undefined offset: 9 in C:\wamp\www\SprintWeb\download.php on line 5
sir i think

$result->fetch_assoc();

here is problem , data can not be fetched ...

0

Make sure that your code returns a result from your query first. So, make this work:

<?php
include("conn1.php");
$query="SELECT * FROM tentb";
$result=$conn1->query($query);
$row = $result->fetch_assoc();
print_r($row);
?>
0

Hye guys
I got id value via session variable .
Please, check my code

<?php
    include("conn1.php");
    session_start();
    $id=$_SESSION['var'];
    $query="SELECT * FROM tentb WHERE id=".$id ;
    $result=$conn1->query($query);
    while ($row= $result->fetch_assoc()){
         $filename=$row['filename'] ;
         $filemime=$row['fildata'];
         $filesize=$row['filesize'];
         $filetype=$row['filetype'];
     //print_r($row);
    header("Content-Disposition: attachment;filename=".$filename);
    header('Content-type:'.$filemime.'/pdf');
    header('Content-length:'.$filesize);
    ob_clean();
    flush();

    //echo $filename;
    //mysqli_close($connection);
    exit;                                }
?>

but it does not download file from my database.
when i click on download link it doing nothing.:(

0

Hye guys,
I changed my code

<?php

    //if(isset($id=$_GET['id'])){
        $id=intval($_GET['id']);
    include("conn1.php");
    $query="SELECT * FROM tentb WHERE id=".$id ;
    $result=$conn1->query($query);

    while ($row= $result->fetch_assoc()){
         $filename=$row['filename'] ;
         $filemime=$row['fildata'];
         $filesize=$row['filesize'];
         $filetype=$row['filetype'];
    $file_extension = strtolower(substr(strrchr($filename,"."),1));

           switch ($file_extension) {
               case "wmv": $ctype="pdf"; break;
               default: $ctype="application/force-download";
           }
           // required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

           header("Pragma: public");
           header("Expires: 0");
           header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
           header("Cache-Control: private",false);
           header("Content-Type: application/pdf");
           header("Content-Type: $ctype");
           header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
           header("Content-Transfer-Encoding: binary");
           header("Content-Length: ".@filesize($filename));
           set_time_limit(0);
           @readfile("$fileurl") or die("File not found.");

}
$donwloaded = "downloads + 1";

    if ($_GET["hit"]) {
        mysql_query("UPDATE ibf_movies SET downloads = $donwloaded WHERE id=' $fileid'");

}

?>

it saves file as extention .pdf but does not open it .please check code.

Edited by zebnoon1

0

ok I changed like that the result is same

header("Pragma: public");
           header("Expires: 0");
           header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
           header("Cache-Control: private",false);
           header("Content-Type: application/pdf");
           header("Content-Type: $ctype");
           header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
           header("Content-Transfer-Encoding: binary");
           header("Content-Length: ".@filesize($filesize));
0

when i click download link it opens window to ask save and open file when i click open it dose not open?

0

sir please, help me . i can not solve this problem last 10 days i again changed my code please check but result is same :(

<?php
         include("conn1.php");
        $id=intval($_GET['id']);

    $query="SELECT * FROM tentb WHERE id=".$id ;
    $result=$conn1->query($query);

    while ($row= $result->fetch_assoc()){

         $name=$row['filename'] ;
         $content=$row['fildata'];
         $size=$row['filesize'];
         $type=$row['filetype'];

          header("Content-Disposition: attachment; filename=$name");
          header("Content-length: $size");
          header("Content-type: $type");

    echo $content;
    exit;
         }
?>

this is download.php file ..

1

@zebnoon1 Hi, you were asked multiple times, to reply to some questions with useful information. Calmly read again Pritaeas posts and reply to his requests.

For example, he asked:

What size is the downloaded file?

So the downloaded .pdf file is 0 bytes, few bytes and when opens is like corrupted? Have you tried to open the file into your PHP editor? Because it could be a plain-text file (with .pdf extension) and more importantly with a PHP error generated by your script. If this is so, then that error could help a lot to understand what happens.

So read again Pritaeas posts and reply to his requests.

Votes + Comments
:)
0

Dear Guys, please, accept my appologize. but i answered all post of Pritasea and other guys. Anyways please, come to my problem. Now i littil bit solved.
II created aaddtender.php fle for upload file , it works normaly it uploads name of file(VARCHAR), type of file(VARCHAR),size of file(INT) and off course data of file(mediumblob) in database.
then created a download.php file for download file against id.

<?php
    include("conn1.php");
    //session_start();
    //$id=$_SESSION['var'];
    if (isset($_GET['id'])){
    $id=$_GET['id'];

    $query="SELECT * FROM tentb WHERE id=".$id ;
    $result=$conn1->query($query);
    while ($row= $result->fetch_assoc()){
         $name=$row['filename'] ;
         $content=$row['filedata'];
         $size=$row['filesize'];
         $type=$row['filetype'];
    //print_r($row);
          header("Content-Disposition: attachment; filename=".$name);
          header("Content-length:".$size);
          header("Content-type:". $type);

    echo $content;
    exit;
         }
         }
?>

thanks guys.....
Please, check my code bellow.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.