Debt Consolidation - Synchronize your Files - Turquoise Rings - Debt Consolidation - Debt Consolidation

PDA

View Full Version : rename, missing extention


promotingspace.net
Aug 21st 2007, 9:52 pm
Hi
I am still playing with an upload file script and having problem.
I upload and copy the files but cannot hash its name.
i use this code but the result is missing extention and so the file will not be opened
what is the solution?
thanks
<?php
$name= $_FILES["file"]["name"];
$ar=explode(".",$name);
$ext=$ar[1];
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/" . $_FILES["file"]["name"]);
$newname=md5(time());
rename('uploads/'. $_FILES["file"]["name"],'uploads/'.$newname.$ext);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
?>

nico_swd
Aug 22nd 2007, 12:25 am
$newname=md5(time()) . '.' . end(explode('.', $_FILES['file']['name']));


Don't rely on the extension being $ar[1], because the file can have a lot of dots, and faking the extension would be super easy.

And remove this line:

rename('uploads/'. $_FILES["file"]["name"],'uploads/'.$newname.$ext);


Put the new name directly in the second parameter of move_uploaded_file().