PDA

View Full Version : creating a file, download, then delete


thesavior
07-18-2006, 05:26 PM
okay, what i am trying to do is this.

I have a file, that i don't want people to know about, so I will copy that file to a different name when the script is executed, then i will prompt the user to download that file, then when it is downloaded, delete it.

What do i use to prompt the user for download but still stay on that page?

So im planning on using copy, then someway to prompt the user, then use unlink to delete the file.

So any ideas how to put this all together to make it work?

thunderhoster
07-18-2006, 05:39 PM
well, if you put the file outside the webserver's root, there's no need for all that copy-move-delete trouble...

I've got a great script for downloading, I can customize it for your needs... add me to msn

thesavior
07-18-2006, 07:22 PM
added.

But about the server root, i don't want to have the file out of the server root.

thunderhoster
07-19-2006, 01:46 AM
Problem solved, the function given was:


function getFile($filepath) {

$file_extension = strtolower(substr(strrchr($filepath,"."),1));

switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: ".$ctype."");
header("Content-Disposition: attachment; filename=\"".basename($filepath)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filepath));
readfile($filepath);
}

thesavior
07-19-2006, 03:11 AM
yes, thanks. That did it for me.