Jump to content

Recommended Posts

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

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.