note 118138 added to function.move-uploaded-file
| From: | r3wt | Date: | Tue, 13 Oct 2015 06:46:47 +0000 |
| Subject: | note 118138 added to function.move-uploaded-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203945@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 209.33.68.19
----
Manual Page -- http://php.net/manual/en/function.move-uploaded-file.php
Edit -- https://master.php.net/note/edit/118138
Del: integrated -- https://master.php.net/note/delete/118138/integrated
Del: useless -- https://master.php.net/note/delete/118138/useless
Del: bad code -- https://master.php.net/note/delete/118138/bad+code
Del: spam -- https://master.php.net/note/delete/118138/spam
Del: non-english -- https://master.php.net/note/delete/118138/non-english
Del: in docs -- https://master.php.net/note/delete/118138/in+docs
Del: other reasons-- https://master.php.net/note/delete/118138
Reject -- https://master.php.net/note/reject/118138
Search -- https://master.php.net/manage/user-notes.php