monkeytooth Posted March 24, 2011 Share Posted March 24, 2011 I have a form with 2 inputs specific to file uploads (where one day I may add more either through a dynamic layer of adding more than, or just might put 2 or 3 more fields). I can get a single file to upload without issue, but i seem to be having issues trying to get more than one at a time. What is the best way to handle this? I seem to be completely lost on this. Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/ Share on other sites More sharing options...
MrXHellboy Posted March 24, 2011 Share Posted March 24, 2011 Whats your code ? If you have a 1 file uploaded , and you succeeded, you probably are able to loop through the $_FILES array Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1191633 Share on other sites More sharing options...
monkeytooth Posted March 24, 2011 Author Share Posted March 24, 2011 $destination_path = "photo-uploads/"; $result = 0; $newName = fileNameSafety(basename($_FILES['photo_1']['name'])); //echo "<br />".$newName."<br />"; $target_path = $destination_path . $newName; if(@move_uploaded_file($_FILES['photo_1']['tmp_name'], $target_path)) { //done } else { //error } thats my existing bit, I know I have to round it off a bit to cut off specific file types an all else, and plan to tempt to do that piece next. but this is the working piece for the single, not sure how to follow that through with a multiple file concept.. one reason being which I should have mentioned in my first post and realize now that I didnt is, only one of my currently 2 uploads is required, second one is optional if i have to do this through some static messure then whatever is cleaver so long as I can get at least 1 file required second one optional thats my biggest thing right now Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1191656 Share on other sites More sharing options...
monkeytooth Posted March 24, 2011 Author Share Posted March 24, 2011 Loop through the Array? Not sure if I follow exactly what you mean with that. Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1191862 Share on other sites More sharing options...
Bl4ckMaj1k Posted March 24, 2011 Share Posted March 24, 2011 Ouch that must suck!!! Yepp, it goes in there. I didn't even notice it was missing from your code. Glad everything is working now, happy coding. Bl4ck Maj1k P.S. There are easier ways to handle links in your message. You should give them a read-up, potentially save yourself some time and headaches LOL. Good luck bro. Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1191934 Share on other sites More sharing options...
monkeytooth Posted March 24, 2011 Author Share Posted March 24, 2011 wha? Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1191942 Share on other sites More sharing options...
Bl4ckMaj1k Posted March 24, 2011 Share Posted March 24, 2011 Wow sorry I have so many threads up that I must've posted in the wrong one....sorry about that bro. Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1191949 Share on other sites More sharing options...
monkeytooth Posted March 24, 2011 Author Share Posted March 24, 2011 no problems Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1191955 Share on other sites More sharing options...
monkeytooth Posted March 25, 2011 Author Share Posted March 25, 2011 Still a little stuck on the idea of looping through multiple files with _FILES, as someone mentioned prior. If someone could show me an example or point me in the right direction I would be appreciative. As I said I am kinda lost on this, was a couple days ago, still am at that. I haven't really got anything new to show for myself as to how I am trying to handle it. So yea, I am just stuck :'( Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1192085 Share on other sites More sharing options...
monkeytooth Posted March 26, 2011 Author Share Posted March 26, 2011 I Hate to do this, but I am bumping it. I still need a bit of help on this, does anyone have any insight as to what the best way is to cycle through this array of _files mentioned, ive tried a couple things failed, and i just want to be done with this piece at this point so an can move on to the next Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1192483 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2011 Share Posted March 26, 2011 See this post - http://www.phpfreaks.com/forums/index.php?topic=328359.msg1545502#msg1545502 Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1192488 Share on other sites More sharing options...
monkeytooth Posted March 26, 2011 Author Share Posted March 26, 2011 oh you rock! course im kicking myself now.. cause I was approaching it similar but horribly in the wrong direction. Maybe just over frustrated with it.. Anyway thank you Ill give that a shot in a little while and see how it works out for me. If i do a count() on $_FILES will that give me an accurate count? 0 for none, 20 for 20? Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1192499 Share on other sites More sharing options...
PFMaBiSmAd Posted March 26, 2011 Share Posted March 26, 2011 If you want a count of the files that were uploaded, you would need to examine the ['error'] element - http://us.php.net/manual/en/features.file-upload.errors.php A 0 value indicates a file was successfully uploaded. A 4 indicates the file field was left empty. Any other number indicates an error with the uploaded file. Quote Link to comment https://forums.phpfreaks.com/topic/231570-struggling-with-uploads/#findComment-1192506 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.