Jump to content

php code needed to download a cv saved in mysql


bindiya

Recommended Posts

I have a webpage where the candidates can attach their resumes  and send to the admin.These attachments are saved in the mysql db as blob datatype.In another webpage the admin needs to download all this resumes and see the content.

How will i code for that.

 

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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;
?>

 

Link to comment
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.