Jump to content

php code needed to download a cv saved in mysql


bindiya

Recommended Posts

Do you store the file extension in the database aswell?

 

All you really need to do is create a file called something like download.php that will connect to the mysql and echo out the data after you have sent some headers..

Here is what I have used in the past:

header('Content-Description: File Transfer');
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename='.$the_file_name;
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
echo $data_from_sql;

Ok then..

<?php

// download.php example file // The query will need to be adjusted obviously 

$user = 'Bob';

$sql = "SELECT `ext`, `blob` FROM `downloads` WHERE `user` = '".$user.'";
$sql_query = mysql_query($sql);
$data = mysql_fetch_array($sql_query);

$the_file = $user . 'CV.' . $data['ext'];

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$the_file;
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo $data['blob'];
exit;
?>

 

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.