Renaming files using PHP

suhas93's Avatar, Join Date: Mar 2010
Light Poster
Hi,

I have a file on another server (say "something.com/1122.doc")

Can I have a renaming engine (using PHP?) So, that when visitors click on download, the file should be renamed to somethingmeaningful.doc

Suhas
0
loyo's Avatar, Join Date: Feb 2010
Go4Expert Member
In your download script, you can give a new name to something.com/1122.doc, when somebody visited this script, it should copy the Original file to the target file,and then ,use the function header("location: newfilename path"); to visit the new file.
<?php
copy("1122.doc", "newfile.doc");
header("location: newfile.doc");
?>
0
suhas93's Avatar, Join Date: Mar 2010
Light Poster
thank you! thats a great idea!

is there a script that deletes the file after download?

ok i'm cheap
0
loyo's Avatar, Join Date: Feb 2010
Go4Expert Member
try unlink("newfile.doc"); after performing header();
I don't know whether it can achieve you need.