note 118138 deleted from function.move-uploaded-file by cmb
| From: | cmb@php.net | Date: | Wed, 16 Dec 2015 15:00:54 +0000 |
| Subject: | note 118138 deleted from function.move-uploaded-file by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-204396@lists.php.net to get a copy of this message | ||
Note Submitter: r3wt
----
A safer alternative which creates a random-ish name, "moves" the file and returns the new
name.
<?php
function move_file($file,$ext,$upload_dir='/uploads/')
{
$body = file_get_contents($file);
$name = md5($body).'-'.time().$ext;
$f = fopen($upload_dir.$name,'w+');
fwrite($f,$body);
fclose($f);
return $name;
}
?>