shanejeffery86 Posted September 24, 2009 Share Posted September 24, 2009 Hey all. Got an odd file upload issue and I am perplexed. $i = 0; foreach($_FILES as $file){ if($file['name'] != ''){ if($i == 0){ $target_path = "../account_images/small/"; $custom_image = "http://www.khaccounts.net/account_images/small/" . basename($file['name']); } else { $target_path = "../account_images/large/"; $screenshot . "_" . $i = "http://www.khaccounts.net/account_images/large/" . basename($file['name']); } $target_path = $target_path . basename($file['name']); if(!move_uploaded_file($file['tmp_name'], $target_path)){ echo "Failure to upload file: " . $file['name'] . ". Please contact Knucklehead for further troubleshooting."; die; } } $i++; } So, what I want to do is run through my $_FILES global and run a series of actions against each element of that $_FILES global. I do foreach statement to make things more simplistic. What I want to do is if the picture is the first one of the bunch (the custom image), then I want it to upload to the /account_images/small directory and if it beyond that, I want it to go to the /account_images/large directory. What is happening in this code is that the first file, the custom image is getting uploaded to the proper /small folder, and then 2nd image is getting uploaded to the /large folder, and then the rest of the images are being uploaded back to the small folder when they should be going to large folder. Am I missing an error in my code or something? If I comment out everything below the if/else statement that creates the $target_path the first time around and then do an echo, the target paths are correct. No idea. You guys have any!? Thanks! Link to comment https://forums.phpfreaks.com/topic/175305-solved-files-upload-issue-urgent/ Share on other sites More sharing options...
shanejeffery86 Posted September 24, 2009 Author Share Posted September 24, 2009 Figured it out. Stupid logic on my end. $start = 0; foreach($_FILES as $file){ if($file['name'] != ''){ $target_path = "../account_images/large/"; if($start == 0){ $target_path = "../account_images/small/"; $custom_image = "http://www.khaccounts.net/account_images/small/" . basename($file['name']); } else { $screenshot[$start] = "http://www.khaccounts.net/account_images/large/" . basename($file['name']); } $target_path = $target_path . basename($file['name']); if(!move_uploaded_file($file['tmp_name'], $target_path)){ echo "Failure to upload file: " . $file['name'] . ". Please contact Knucklehead for further troubleshooting."; die; } } $start++; } Thanks anyways! Link to comment https://forums.phpfreaks.com/topic/175305-solved-files-upload-issue-urgent/#findComment-923925 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.