note 22631 added to features.file-upload.multiple

From: Date: Tue, 25 Jun 2002 17:30:30 +0000
Subject: note 22631 added to features.file-upload.multiple
Groups: php.notes 
Request: Send a blank email to php-notes+get-32185@lists.php.net to get a copy of this message
Here's working file upload code snippet that works for any number of files "out of the box." It assumes that each input of type file is named 'files[]', although this could be modified so that it just iterated through the array $HTTP_POST_FILES. It will not overwrite existing files. It could be improved with more checks (ie, mime types) but this does what I need quite admirably. Let me know if you find an inefficiency. $path_to_file = '/var/www-uploads/'; $files = $HTTP_POST_FILES['files']; if (!ereg("/$", $path_to_file)) $path_to_file = $path_to_file."/"; foreach ($files['name'] as $key=>$name) { if ($files['size'][$key]) { // clean up file name $name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($name) ) ) ); $location = $path_to_file.$name; while (file_exists($location)) $location .= ".copy"; copy($files['tmp_name'][$key],$location); unlink($files['tmp_name'][$key]); echo "\n<br>Successfully uploaded file: $name."; } } -- http://www.php.net/manual/en/features.file-upload.multiple.php http://master.php.net/manage/user-notes.php?action=edit+22631 http://master.php.net/manage/user-notes.php?action=delete+22631 http://master.php.net/manage/user-notes.php?action=reject+22631

« previous php.notes (#32185) next »