note 51569 added to features.file-upload

From: Date: Mon, 04 Apr 2005 15:08:12 +0000
Subject: note 51569 added to features.file-upload
Groups: php.notes 
Request: Send a blank email to php-notes+get-87433@lists.php.net to get a copy of this message
I looked high and low for a simple way to rename files as they are uploaded to prevent users from overwriting each others files. Below is the script I came up with. <?php foreach( $_FILES["screenshots"]["error"] as $key => $error ) { if( $error == UPLOAD_ERR_OK ) { $tmp_name = $_FILES["screenshots"]["tmp_name"][$key]; $original_name = $_FILES["screenshots"]["name"][$key]; $tmp_array = preg_split( "/\\\/",$tmp_name ); $file_name = $tmp_array[count($array)-1]; $extension = preg_replace( "/(.*)\.([a-z]+)$/","$2",$original_name ); $new_name = preg_replace( "/(.*)\.([a-z]+)$/","$1.$extension",$file_name ); move_uploaded_file( $tmp_name,"./screenshots/$new_name" ); } } ?> I started with the generic multiple file upload script in the documentation above and worked from there. ---- Manual Page -- http://www.php.net/manual/en/features.file-upload.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51569 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51569&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51569&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51569&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51569&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51569&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51569&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87433) next »