zoetway Posted August 8, 2006 Share Posted August 8, 2006 Hi everyone, In an attempt to upload multiple files from a HTML form I can't access file['tmp_name'] more than once ?!Here's what I'm trying:[code]foreach($_FILES as $image){ if($image['tmp_name'] != ""){ echo($image['tmp_name']."<BR>"); $uploadPath = '../images/products/'; $smallImage = uploadFile($image["tmp_name"], $uploadPath); $mediumImage = uploadFile($image["tmp_name"], $uploadPath); $largeImage = uploadFile($image["tmp_name"], $uploadPath); }}[/code]I can post the rest of the functions if needed. This only gives me $smallImage on the server, $mediumImage and $largeImage don't exist (empty strings, no filename returned by uploadFile). Does this have anything to do with the time needed to upload the first image?phpversion = 4.3.10provider = Lycos.nlThanks in advance for looking at my code attempt.--Rob Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 8, 2006 Share Posted August 8, 2006 Make sure that your form fields got names like [code]<input type="file" name="image[]" /><input type="file" name="image[]" /><input type="file" name="image[]" />[/code]Then you can get the information about the file this way:[code]echo $_FILES['name'][0]; // File 1echo $_FILES['name'][1]; // File 2echo $_FILES['name'][2]; // File 3[/code] etc. Quote Link to comment Share on other sites More sharing options...
zoetway Posted August 8, 2006 Author Share Posted August 8, 2006 Thanks Daniel0, that makes sense. But it doesn't explain why the first call to $image['tmp_name'} succeeds and the remainig two don't. Or am I missing the point here?The problem is I use multiple form input fields to send multiple files. Each time a file is browsed from the local drive it's displayed in a file list on the site through a javascript and it looks like the same input field used to browse the file is empty again. It's stick-man's multifile javascript (http://the-stickman.com/web-development/javascript/updated-upload-multiple-files-with-a-single-file-element/). Quote Link to comment Share on other sites More sharing options...
glenelkins Posted August 8, 2006 Share Posted August 8, 2006 Basically if you dont use the form field name as an array IE <input type="file" name="Image[]"> the php script will only loop through 1 of the file boxes as It has no idea there are others to look through Quote Link to comment Share on other sites More sharing options...
zoetway Posted August 11, 2006 Author Share Posted August 11, 2006 Right, but still, I'm using only one file box right now and call the same variable 3 times (even echo doesn't do anything). I changed the page to a form with one input box (removed the javascript) with a name file_1, pass it through POST with $_FILE['file_1']['tmp_name'] and put it in $files. If I echo $files 3 times I get the tmp_name once and two empty lines ???? Quote Link to comment Share on other sites More sharing options...
zoetway Posted August 11, 2006 Author Share Posted August 11, 2006 Found out wat I was doing wrong. The function [i]move_uploaded_file[/i] deletes files from the tmp directory that is used to store the POST $_FILES. I was trying to send that file to my upload function ::). Got around it by uploading only one file and usnig the[i] copy[/i] function to create two duplicates which can then be resized....Sounds like an awful lot of work for what I wanted to do. I'm sure there's an more efficient way but this'll do for now. I am using the methods described by Daniel0 and glenelkins now (thanks again both of you!). Quote Link to comment 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.