dlebowski Posted September 7, 2007 Share Posted September 7, 2007 With the code below, I can get the first Image in my array to upload correctly. I cannot get the others to upload after that. Can someone tell me what is wrong? The array is being generated correctly, but nothing is being grabbed other than first entry. $ImageAuctionDate=$_POST['SelectLotAuctionDate']; echo 'Upload result:<br>'; $uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."/images/".$ImageAuctionDate."/"; $target_encoding = "ISO-8859-1"; echo '<pre>'; if(count($_FILES) > 0) { $arrfile = pos($_FILES); $uploadfile = $uploaddir . iconv("UTF-8", $target_encoding,basename($arrfile['name'])); if (move_uploaded_file($arrfile['tmp_name'], $uploadfile)) echo "File is valid, and was successfully uploaded.\n"; } else echo 'No files sent. Script is OK!'; echo 'Here is some more debugging info:'; print_r($_FILES); echo "</pre>"; } Result: File is valid, and was successfully uploaded. Here is some more debugging info:Array ( [LotImage1] => Array ( [name] => DSCF3088.JPG [type] => image/jpeg [tmp_name] => /tmp/phpEb0Wvs [error] => 0 [size] => 111168 ) [LotImage2] => Array ( [name] => DSCF3092.JPG [type] => image/jpeg [tmp_name] => /tmp/phpjYo1N6 [error] => 0 [size] => 111525 ) [LotImage3] => Array ( [name] => DSCF3116.JPG [type] => image/jpeg [tmp_name] => /tmp/phpagCTNP [error] => 0 [size] => 113969 ) [LotImage4] => Array ( [name] => DSCF3155.JPG [type] => image/jpeg [tmp_name] => /tmp/phpD3Et3D [error] => 0 [size] => 112006 ) [LotImage5] => Array ( [name] => DSCF3088.JPG [type] => image/jpeg [tmp_name] => /tmp/phpRKJrkw [error] => 0 [size] => 111168 ) [LotImage6] => Array ( [name] => DSCF3187.JPG [type] => image/jpeg [tmp_name] => /tmp/phpujkAkt [error] => 0 [size] => 107119 ) ) Link to comment https://forums.phpfreaks.com/topic/68318-solved-only-first-entry-in-array-being-uploaded-to-server/ Share on other sites More sharing options...
gerkintrigg Posted September 7, 2007 Share Posted September 7, 2007 I'd normally use a foreach() loop for array data. It looks to me like you're just doing an if() statement to only activate the code on the first (default) record of the array. Link to comment https://forums.phpfreaks.com/topic/68318-solved-only-first-entry-in-array-being-uploaded-to-server/#findComment-343534 Share on other sites More sharing options...
dlebowski Posted September 7, 2007 Author Share Posted September 7, 2007 I get this error if I change if() to foreach(): Parse error: syntax error, unexpected ')' on line 544 Link to comment https://forums.phpfreaks.com/topic/68318-solved-only-first-entry-in-array-being-uploaded-to-server/#findComment-343658 Share on other sites More sharing options...
dlebowski Posted September 7, 2007 Author Share Posted September 7, 2007 Here is what I finally had to do to take care of it. Works great now. foreach($_FILES as $files ) { $uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."/images/".$LotAuctionDate."/"; $arrfile = $files; $uploadfile = $uploaddir . iconv("UTF-8", $target_encoding,basename($arrfile['name'])); if (move_uploaded_file($arrfile['tmp_name'], $uploadfile)) echo "File is valid, and was successfully uploaded.\n"; } Link to comment https://forums.phpfreaks.com/topic/68318-solved-only-first-entry-in-array-being-uploaded-to-server/#findComment-343784 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.