Jump to content

Struggling with uploads


monkeytooth

Recommended Posts

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.

Link to comment
Share on other sites

	$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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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  :'(

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.