RE: [PHP] HELP WITH UPLOAD REQUIRED!!!!!!!!

From: Date: Tue, 16 Jan 2001 11:15:18 +0000
Subject: RE: [PHP] HELP WITH UPLOAD REQUIRED!!!!!!!!
Groups: php.general 
Request: Send a blank email to php-general+get-34798@lists.php.net to get a copy of this message
Mike, I haven't had a problem. I'm using Apache 1.3.14 with PHP 4.0.3pl1 + 4.0.4. I use the same code on 3 computers (depending on where I am when I'm working on it. Normally it's Win95, but Win2k and WinNT are used as well. The snippet of code I use is: --code 1----- list($scriptBase, ) = explode($HTTP_SERVER_VARS["SCRIPT_NAME"], $HTTP_SERVER_VARS["SCRIPT_FILENAME"]); ------------- --code 2----- { $j=0; for ($i=1;$i<6;$i++) { $addnewName = "photo" . $i; $addnewSize = "photo" . $i . "_size"; if (${$addnewSize} > 0) { copy(${$addnewName}, 'temp/'.$SessionID.'.'.++$j.'.jpg'); $addnewSession['photo'.$j] = 'temp/'.$SessionID.'.'.$j.'.jpg'; unlink (${$addnewName}); } } $addnewSession["photos"] = $j; } ------------- --code 3----- for ($i=1;$i<=$addnewSession["photos"];$i++) { if (!@copy($addnewSession["photo".$i], $scriptBase."/images/property/".$addnewPropertyID.",".$i.".jpg")) { $addnewFileErrors .= " c".$i; } if (!@unlink($addnewSession["photo".$i])) { $addnewFileErrors .= " d".$i; } } ------------- The first line just sets $scriptBase as the base of the web site (so I can use it anywhere, 'cause moving computers may mean different locations, and as all the needs of the site is below the site's root, then I just need to work out where the base of the site is. The next set of code is to move the files to a temp location (until the script deals with them in the third chunk). Someone can upload up to five photos, so this will just go thru each of them, and if there's a file (I know it a photo - the check was done earlier), 'cause it's size is greater than zero, then move it. This code will also group together the photos (if someone uploaded a file in photo1, photo3 and photo4, then 3 will become 2 and so on, so the photos end up as 1, 2, and 3). It also stores the photo's location in the session var, as well as the number of photos. The second lot just moves them to their final location. I haven't tested this code on Linux/Unix servers, but I know it works on Windows/Apache using PHP 4.0.3 and PHP 4.0.4, irrespective on the operating system and where the files are located. See if that helps. I don't know why yours shouldn't work, but I've posted my code so you can see and work with it to help yours. At 09:36 PM 1/15/01, you wrote: I am trying to allow various users to upload their own picture. What I would like to happen is to have the copy statement rename the .jpg image to the username. For example, if the username is mike, then I want the picture to be renamed mike.jpg The following is a snippet of code: <?PHP print "$CUserName" //ensures name is carried over from session if(copy($userfile,"c:/phpweb/userpics/$CUserName.jpg")) { print "Your picture has been uploaded!"; } else { print "Error"; } unlink($userfile) ?> The errors I get are as follows: Warning: unable to open " for reading: Permission denied in c:\phpweb/fuploadconfirm.php on line 15 Warning: Unlink failed (No such file or directory) in c:\phpweb/fuploadconfirm.php on line 31 Line 15 is the if copy($userfile........) line in the above code AND Line 31 is the unlink statement at the end. Thanks, Mike -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net __________________________________________________ Jonathan Wright (DjNA) mail@djna.fsnet.co.uk

« previous php.general (#34798) next »