php problem , help please?

Person X

New member
hi there , i want to uploaded a file and store it in MySQL database,then show the client the download prompt whenever the download link is clicked, now i created everything but when i click the download link and download the file its damaged and cannot be openned , so i guess i messed something about the binary content,here are the steps :

when the upload form is submitted i move the uploaded file to the current directory , read it , encode it and then store it in db,and then delete the file from the current dir :

$file = $_FILES['myfile']['name'];
move_uploaded_file($_FILES['myfile']['tmp_name'],$file);
$open_file = fopen($file,'rb');
$read_file = fread($open_file,filesize($file));
$file_content = base64_encode($read_file;
fclose($open_file);
//now delete the file
unlink($file);

in the download script , i retrieve the data , decode it , and then used the following headers :

header("Content-type: $type");
header("Content-length: $size");
header("Content-Disposition: attachment; filename=$name");
header("Content-Description: file download");
echo $bin_file;//the data decoded with base64_decode

whats wrong exactly and thanks a lot in advance.
 
Back
Top