Jump to content

download scrip


lional

Recommended Posts

Hi

I am trying to write a download script that will enable me to download image files from my web server to my local machine.

The images are in a mysql table and they are grouped by reference no so there might be more that one image that needs to be downloaded based on the reference number. Each image is assigned a unique upload_id

Here is the code for my first script that I pull from mysql baed on the reference number


// Query the database
$query = "SELECT * FROM attachments WHERE ref_no = '$quo_out'";
$result = mysql_query($query, $conn);
while ($row = mysql_fetch_assoc($result)){
$upload_id_out = $row["upload_id"];
$filename_out = $row["filename"];
$filesize_out = $row["filesize"];
// Display the files
$final_file_size = ROUND($filesize_out/1024);  
      // Display each record
print <<<FILES
        <td align="left"><a href="download_images.php?uid=$upload_id_out"><font face="arial" size="2" color="white">$filename_out</a></td>
        <td align="center"><font face="arial" size="2" color="white">$final_file_size kb</td></tr><br>
FILES;
  
}

and here is my download script

$uid_out = $_GET['uid'];
include '../includes/conn_db.php';
$query = "SELECT * FROM attachments WHERE upload_id = '13'";
$result = mysql_query($query, $conn);
while ($row = mysql_fetch_assoc($result)){
$filename_out = $row["filename"];
$filesize_out = $row["filesize"];
$filetype_out = $row["filetype"];

list ($filename_out, $filesize_out, $filetype_out) = mysql_fetch_row($result);

// determine the filename on the server
explode('.',$filename_out);

// check if the file exists
if (file_exists ($filename_out)) {
    
    // send the file
    
    header ("Content-Type: application/$filetype_out");
    header ("Content-disposition: attachment; filename=$filename_out");
    header ("Content-Length: $filesize_out");
    readfile ($filename_out);
    
    $message = '<p>The file has been downloaded.</p>';
    } else {
    $message = '<p><font color="red" size="2" face="arial">The file could not be located on the server.</p>';
    }
}
  

Link to comment
https://forums.phpfreaks.com/topic/124621-download-scrip/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.