note 52070 deleted from features.file-upload by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 17:50:58 +0000 |
| Subject: | note 52070 deleted from features.file-upload by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134316@lists.php.net to get a copy of this message | ||
Note Submitter: Jared
----
If you want a unique filenames to prevent overwritting is to use sha1_file().
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (isset($_FILES['pic']))
{
$file = $_FILES['pic'];
if ($file['error'] == UPLOAD_ERR_OK)
{
$name = sha1_file($file['tmp_name']);
$pathInfo = pathinfo($file['name']);
if (isset($pathInfo['extension']))
$name .= '.'.$pathInfo['extension'];
if (move_uploaded_file($file['tmp_name'], $uploaddir.$name))
{
// ..ok..
}
else
{
// ..failed..
}
}
}
}
?>
Its unlikely 2 files will ever get the same filename, unless they are the same.