note 52070 added to features.file-upload

From: Date: Wed, 20 Apr 2005 14:07:27 +0000
Subject: note 52070 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-88267@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52070 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52070&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52070&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52070&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52070&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52070&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52070&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88267) next »