RCS Posted April 13, 2008 Share Posted April 13, 2008 Will this work the $fileName = $_FILES['file']['name']; $tmpName = $_FILES['file']['tmpName']; $fileSize = $_FILES['file']['size']; $fileType = $_FILES['file']['type']; The same as $fileName2 = $_FILES['file2']['name2']; $tmpName2 = $_FILES['file2']['tmpName2']; $fileSize2 = $_FILES['file2']['size2']; $fileType2 = $_FILES['file2']['type2']; and is thier a better way to write it for ten files?? Quote Link to comment Share on other sites More sharing options...
soycharliente Posted April 13, 2008 Share Posted April 13, 2008 <?php for ($i = 1; $i <= 10; $i++) { $fileName.$i = $_FILES['file.$i']['name.$i']; $tempName.$i = $_FILES['file.$i']['tmpName.$i']; $fileSize.$i = $_FILES['file.$i']['size.$i']; $fileType.$i = $_FILES['file.$i']['type.$i']; } ?> I have no idea if this would work. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 13, 2008 Share Posted April 13, 2008 There's a section in the PHP manual on multiple file uploads. http://www.php.net/manual/en/features.file-upload.multiple.php Quote Link to comment Share on other sites More sharing options...
RCS Posted April 13, 2008 Author Share Posted April 13, 2008 it's not just that simple In my admin area I need to save and upload 10 images to database and sever along with the fields make, description and price so that I can call and display info to a page after. I am a newbie, I have managed to create a script that works using one file with fields make, description and price, now I just need to some how change it so that I can upload 10 files and fields make, description and price.. Someone please help me understand all this. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 13, 2008 Share Posted April 13, 2008 <?php $imagedir = "x"; if (isset($_POST['btnSub'])) { foreach ($_POST['make'] as $k => $make) { $desc = $_POST['desc'][$k]; $price = $_POST['price'][$k]; $tmpname = $_FILES['picfile']['tmp_name'][$k]; $name = $_FILES['picfile']['name'][$k]; $type = $_FILES['picfile']['type'][$k]; // process the data here } } ?> <form method='post' enctype='multipart/form-data'> <?php for ($i=1; $i<=10; $i++) { echo "<fieldset>\n"; echo "<legend>Product $i</legend>\n"; echo "Make <input type='text' name='make[]' /><br/>"; echo "Description <input type='text' name='desc[]' size='60' /><br/>"; echo "Price <input type='text' name='price[]' /><br/>"; echo "Picture <input type='file' name='picfile[]' size='60' /><br/>"; echo "</fieldset><br/>\n"; } ?> <input type='submit' name='btnSub' value='Submit'> </form> Quote Link to comment Share on other sites More sharing options...
RCS Posted April 13, 2008 Author Share Posted April 13, 2008 OK here is my current script if you can follow $fileName = $_FILES['file']['name']; $tmpName = $_FILES['file']['tmpName']; $fileSize = $_FILES['file']['size']; $fileType = $_FILES['file']['type']; <?PHP if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/tif") || ($_FILES["file"]["type"] == "image/psd") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "image/pct") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } include("dbinfo.inc"); include("file_array.inc"); $con = mysql_connect($db_host, $db_user, $db_passwd) or die ("Could not connect to database."); mysql_select_db($db_name) or die ("Unable to connect to select database"); $query = "INSERT INTO upload(name, TYPE, size, content, make, description, price)". "VALUES ('$fileName', '$fileType', '$fileSize', '$content','$_POST[make]','$_POST[description]','$_POST[price]')"; $result=mysql_query($query) or die ("Could not complete query."); ?> And this is the form <form action="upload_file.php" method="POST" enctype="multipart/form-data"> <blockquote> <p align="center"> </p> <p> <label><strong>Id:</strong> <input name="id" type="text" id="id" size="2" maxlength="2"> </label> (Pick id number 1 through 10) <p><label><b>Make:</b></label> <input type="text" name="make" id="make" /></p> <p><label><b>Price:</b></label> <input type="text" name="price" id="price" /></p> <p><label></label> <label><b>Description:</b></label> <textarea name="description" id="description" cols="45" rows="5"></textarea /> </p> <p><p><label for="file"><strong>Filename:</strong></label> <input type="file" name="file" id="file" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong></p> </p> <div align="center"><br /> <label for="file"><strong>Filename:</strong></label> <input type="file" name="file2" id="file2" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong> </p> <div align="center"><br /> </p> <p><label for="file"><strong>Filename:</strong></label> <input type="file" name="file3" id="file3" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong></p> </p> <div align="center"><br /> <label for="file"><strong>Filename:</strong></label> <input type="file" name="file4" id="file4" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong> </p> <div align="center"><br /> </p> <p><label for="file"><strong>Filename:</strong></label> <input type="file" name="file5" id="file5" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong></p> </p> <div align="center"><br /> <label for="file"><strong>Filename:</strong></label> <input type="file" name="file6" id="file6" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong> </p> <div align="center"><br /> </p> <p><label for="file"><strong>Filename:</strong></label> <input type="file" name="file7" id="file7" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong></p> </p> <div align="center"><br /> <label for="file"><strong>Filename:</strong></label> <input type="file" name="file8" id="file8" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong> </p> <div align="center"><br /> </p> <p><label for="file"><strong>Filename:</strong></label> <input type="file" name="file9" id="file9" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong></p> </p> <div align="center"><br /> <label for="file"><strong>Filename:</strong></label> <input type="file" name="file10" id="file10" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong> </p> <div align="center"><br /> <input type="submit" name="submit" value="Save" /> </p> </div> </blockquote> <blockquote><blockquote> </blockquote> </blockquote> </form> I need 1 desicription, 1 make, 1 price and 10 photos all in one database row for one product. I have created it so that it works now with 1 desicription, 1 make, 1 price and 1 photo, then I just copied and pasted the script 9 other times and thought it would work but I now get query issues. can you follow what I am trying to do and will that script you created work for what I'm doing. the script you made looks like it creates 10 desicription, 10 make, 10 prices and 10 photos?? Please help me figure this out, I'm just not understanding the logic. Your help is greatly appreciated. Thanks Quote Link to comment Share on other sites More sharing options...
RCS Posted April 14, 2008 Author Share Posted April 14, 2008 why will no one help me with this??? Quote Link to comment Share on other sites More sharing options...
RCS Posted April 14, 2008 Author Share Posted April 14, 2008 ??? ??? ??? ??? ??? ??? ??? ??? Quote Link to comment Share on other sites More sharing options...
RCS Posted April 14, 2008 Author Share Posted April 14, 2008 Is what i'm doing make any sense?? Why am I getting no response???????? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 14, 2008 Share Posted April 14, 2008 You shouldn't bump your posts unless there is no response after 3 or 4 hours. Be patient. Bumping once an hours is not good. Nobody likes a whiner. Ken Quote Link to comment Share on other sites More sharing options...
Barand Posted April 14, 2008 Share Posted April 14, 2008 why will no one help me with this??? I've helped you. In your original post of this problem you received good advice on how better to restructure your code. I guess people might be tired of the same topic reappearing. or by "not helping" do you mean "why has no-one rewritten it for me"? Anyway, here's a revision to my last post. <?php $imagedir = "x"; if (isset($_POST['btnSub'])) { $desc = $_POST['desc']; $price = $_POST['price']; $make = $_POST['make']; foreach ($_FILES['picfile']['name'] as $k => $name) { $tmpname = $_FILES['picfile']['tmp_name'][$k]; $type = $_FILES['picfile']['type'][$k]; // process each pic here } // update db here } ?> <form method='post' enctype='multipart/form-data'> <?php echo "Make <input type='text' name='make[]' /><br/>"; echo "Description <input type='text' name='desc[]' size='60' /><br/>"; echo "Price <input type='text' name='price[]' /><br/>"; for ($i=1; $i<=10; $i++) { echo "<fieldset>\n"; echo "<legend>Picture $i</legend>\n"; echo "<input type='file' name='picfile[]' size='60' /><br/>"; echo "</fieldset><br/>\n"; } ?> <input type='submit' name='btnSub' value='Submit'> </form> Quote Link to comment Share on other sites More sharing options...
RCS Posted April 14, 2008 Author Share Posted April 14, 2008 Yeah I agree that you have help me with reducing my code and thank yopu very much but thats not the only issue. I have been trying for two weeks now to create a script that has 1 make field, 1 description field, 1 price field and 10 upload fields. All I'm trying to do is send that info to the database that I created and upload the images to database and server for me to display 1 image and make, description, price on a page and the other 9 images on another page. I have rewrote the code like 40 times and just can figure it out, not one person has help with the origanal problem. I have a script now that I created to upload 1 make field, 1 description field, 1 price field and 1 image to database and I display the info on a catalog page, the only change that I want to make is so that I can upload 9 other files at the same time and add them to server folder and database row with the rest. Not one person has help me to do this, not once have I asked anyone to write the script just asking how to modify mine to work with 9 other images. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 14, 2008 Share Posted April 14, 2008 Not one person has help me to do this, not once have I asked anyone to write the script just asking how to modify mine to work with 9 other images. That's exactly what I have done. Where I put // process each pic here put your code to process an uploaded pic. BTW, your post here was sufficient. Two PMs overdid it. This is my last post on this topic. Quote Link to comment Share on other sites More sharing options...
RCS Posted April 14, 2008 Author Share Posted April 14, 2008 Yeah thanks for your help!! Quote Link to comment Share on other sites More sharing options...
Barand Posted April 14, 2008 Share Posted April 14, 2008 Correction: This is my last post on your topics. Quote Link to comment Share on other sites More sharing options...
RCS Posted April 14, 2008 Author Share Posted April 14, 2008 No problem thanks for all your hard work!!! It's good to see that when someone needs your help you just drop a line with no explanation and get upset when someone doesn't understand. No you just drop a line of code so that you can act like you helped. Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 It's all great that it makes sense in your head but I would not be here if it made any sense in mine. Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 No Explanation??? <?php $imagedir = "x"; if (isset($_POST['btnSub'])) { foreach ($_POST['make'] as $k => $make) { $desc = $_POST['desc'][$k]; $price = $_POST['price'][$k]; $tmpname = $_FILES['picfile']['tmp_name'][$k]; $name = $_FILES['picfile']['name'][$k]; $type = $_FILES['picfile']['type'][$k]; // process the data here } } ?> <form method='post' enctype='multipart/form-data'> <?php for ($i=1; $i<=10; $i++) { echo "<fieldset>\n"; echo "<legend>Product $i</legend>\n"; echo "Make <input type='text' name='make[]' /><br/>"; echo "Description <input type='text' name='desc[]' size='60' /><br/>"; echo "Price <input type='text' name='price[]' /><br/>"; echo "Picture <input type='file' name='picfile[]' size='60' /><br/>"; echo "</fieldset><br/>\n"; } ?> <input type='submit' name='btnSub' value='Submit'> </form> Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 as you can see my script is nothing like yours so how am I to understand yours with no explanation?? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted April 15, 2008 Share Posted April 15, 2008 Code, by it's nature, is pretty self explanatory. Barand didn't do anything exotic. Well, maybe a multidimensional array...but that's not exotic. Everything is done for you except the part where you actually process the data, and Barand even told you where to put that. In addition to that, Barand went back and rewrote part of his code to take into account the multiple file uploads: http://www.phpfreaks.com/forums/index.php/topic,192347.msg865206.html#msg865206 So, what explanation do you want? Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 15, 2008 Share Posted April 15, 2008 why will no one help me with this??? ??? ??? ??? ??? ??? ??? ??? ??? Is what i'm doing make any sense?? Why am I getting no response???????? Yeah thanks for your help!! No problem thanks for all your hard work!!! It's good to see that when someone needs your help you just drop a line with no explanation and get upset when someone doesn't understand. No you just drop a line of code so that you can act like you helped. It's all great that it makes sense in your head but I would not be here if it made any sense in mine. Let's see..... Bumping your post 3 times within an hour and acting like the fact that you haven't gotten an answer that you deem worthy is a major flaw on the part of the people on this board. Why would anyone WANT to help someone with THAT attitude. I'd ignore you too. The people on this board are extremely helpful to just about anyone. Do you REALLY think that out of the hundreds (maybe even thousands) of people who post here, they decided all of a sudden to pick YOU to treat badly? Don't think so! It's NOT the fact that you didn't understand the answers provided that anyone has a problem with--it's your ATTITUDE. This is EASILY my favorite resource when I'm looking for info on PHP. I search here for the answer, if I don't find an answer here, I search the php.net site. If I still haven't found an answer, I ASK here. If I haven't gotten a response by the next day, I THEN bump my post. Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 I understand that I was not saying he didn't help I was saying that his first post left me with way to many questions, and that he didn't really take the time to explain the code before cliaming that he help and problem solved. I am very new at this and am having a hard time following arrays at this time. He showed me how to make my code more clean, but now I have no idea how to insert the array data to my database. with one file it's simple, with an array I have no idea how to INSERT INTO upload (?????). So the problem is not solved in my eyes and that why you keep seeing this post. He got mad and said that no one would help cause it's getting old, well if I still have so many questions how is the issue solved. Is it just that no one wants to take the time to explain?? I thought I could come here for help?? I have basic php skills, I 'm not asking anyone to write the script for me and I don't think what I'm asking requires a rocket scientist to answer, so I'm not sure why the issues. I just really need to solve my problem that's all. I appreciate all the help. Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 why will no one help me with this??? ??? ??? ??? ??? ??? ??? ??? ??? Is what i'm doing make any sense?? Why am I getting no response???????? Yeah thanks for your help!! No problem thanks for all your hard work!!! It's good to see that when someone needs your help you just drop a line with no explanation and get upset when someone doesn't understand. No you just drop a line of code so that you can act like you helped. It's all great that it makes sense in your head but I would not be here if it made any sense in mine. Let's see..... Bumping your post 3 times within an hour and acting like the fact that you haven't gotten an answer that you deem worthy is a major flaw on the part of the people on this board. Why would anyone WANT to help someone with THAT attitude. I'd ignore you too. The people on this board are extremely helpful to just about anyone. Do you REALLY think that out of the hundreds (maybe even thousands) of people who post here, they decided all of a sudden to pick YOU to treat badly? Don't think so! It's NOT the fact that you didn't understand the answers provided that anyone has a problem with--it's your ATTITUDE. This is EASILY my favorite resource when I'm looking for info on PHP. I search here for the answer, if I don't find an answer here, I search the php.net site. If I still haven't found an answer, I ASK here. If I haven't gotten a response by the next day, I THEN bump my post. I have just found that if your issues involve more than just a few lines of code, then no one like to respond. maybe it's just me. Look at my other posts and see if you can see a bad attitude. I have been seeking answers to the same problem the whole time and still can't solve the issues Quote Link to comment Share on other sites More sharing options...
doni49 Posted April 15, 2008 Share Posted April 15, 2008 If you didn't understand what he posted, you should've asked questions about his code so that you could understand it. THAT would've been totally justified. But instead, you posted your own revised code--A LOT of code--expecting everyone else to read and understand your code. That's where this first went awry. STRIKE ONE. But then bad attitude kicked in. STRIKE TWO. When you come back and bump your post so quickly--and worse, add comments like "why isn't anyone helping"--it just comes across as obnoxious and implies that you think the members of this board are here to serve you specifically. NOBODY here gets paid for helping people--everyone here is a volunteer. And to send someone one--let alone two--PM message because you haven't gotten a response that you like is above and beyond obnoxious. I reiterate--NOBODY got mad because you didn't understand the code. You may not be asking anyone to write your code for you. But you are certainly expecting everyone else to read and understand YOUR code (to much code to digest here) instead of TRYING to understand the code that's been provided to you and asking any questions that you may have. You've said that you don't understand why nobody wants to take the time to explain. Well tell us what about the code you don't understand. If I can answer the question, I will. Quote Link to comment Share on other sites More sharing options...
RCS Posted April 15, 2008 Author Share Posted April 15, 2008 I'm sorry to come across that way. Thanks to anyone who takes the time to help me out with this. Now I have a script that I made that submits info form info to my database with this form info is an image. The image not only gets submitted to my database but also downloaded to my server. After making this script, I desided that if would be more useful to me if I made it so that it submits and saves 10 images and not just one. My current code if Array <?php $fileName = $_FILES['file']['name']; $tmpName = $_FILES['file']['tmpName']; $fileSize = $_FILES['file']['size']; $fileType = $_FILES['file']['type']; ?> Form <form action="upload_file.php" method="POST" enctype="multipart/form-data"> <blockquote> <p align="center"> </p> <p> <p><label for="file"><strong>Filename:</strong></label> <input type="file" name="file" id="file" /> <input type="hidden" name="MAX_FILE_SIZE" value="100000000000000"> <strong>(Note pictures must be sized to 182 X 124 pixels)</strong></p> <p><label><b>Make:</b></label> <input type="text" name="make" id="make" /></p> <p><label><b>Price:</b></label> <input type="text" name="price" id="price" /></p> <p><label></label> <label><b>Description:</b></label> <textarea name="description" id="description" cols="45" rows="5"></textarea /> </p> <div align="center"><br /> <input type="submit" name="submit" value="Save" /> </p> </div> </form> Upload Script <?PHP if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/tif") || ($_FILES["file"]["type"] == "image/psd") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "image/pct") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } include("dbinfo.inc"); include("file_array.inc"); $con = mysql_connect($db_host, $db_user, $db_passwd) or die ("Could not connect to database."); mysql_select_db($db_name) or die ("Unable to connect to select database"); $query = "INSERT INTO upload(name, TYPE, size, content, make, description, price)". "VALUES ('$fileName', '$fileType', '$fileSize', '$content','$_POST[make]','$_POST[description]','$_POST[price]')"; $result=mysql_query($query) or die ("Could not complete query."); ?> Please help me to understand how to do this?? 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.