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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.