This is a discussion on "Easy Question - for someone" within the PHP Forum section. This forum, and the thread "Easy Question - for someone are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Easy Question - for someone
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
Easy Question - for someone
Well, I've tried all my tricks but nothing works so far...
Problem: I have a form that allows upload of 3 images. If only 1 image is uploaded - two empty - the script finishes img-1 and continues to the next image function to process img-2 and - of course - errors because there is no image-2. Solution: I need an IF statement (or somthing) to bypass the img-2 and img-3 functions (if empty), but the $_FILES['img-2'] is an array and the EMPTY, ISSET, and the "!" options do not work since the array always seems to return some value and I cannot set img-2 and img-3 to 0 for the db Question: How do you bypass an empty Array? Code: The first function works fine. The script stops at the second function due to invalid parameter passed to the function... if(!isset($_FILES['img1'])) { $img1 = 0; }else{ $img= $_FILES['img1']; $img1 = myimgupload($img); } if(!isset($_FILES['img2'])) { $img2 = 0; }else{ $img= $_FILES['img2']; $img2 = myimgupload($img); } if(!isset($_FILES['img3'])) { $img3 = 0; }else{ $img= $_FILES['img3']; $img3 = myimgupload($img); } Have not seen an example in my studies so far... Thanks to the list in advance for your help!! David |
|
|
|
#2
|
|||
|
|||
|
Re: Easy Question - for someone
|
|
#3
|
|||
|
|||
|
Re: Easy Question - for someone
Thanks Pheonix!!
I tried your approach and it had the same results of failing if an image were not entered. (But I really like the small foot print in the script so I will use it for sure if I can figure out what I am doing wrong... Maybe I am not using the form post correctly. I provide 3 boxes for the client to enter the 3 images. the code is listed below: <b>Photo 1</b> <input type="file" name="img1"><br /> <b>Photo 2</b> <input type="file" name="img2"><br /> <b>Photo 3</b> <input type="file" name="img3"> I POST everything from the form to the script so img1, img2, and img3 all go to the script - and all need to go to the file and db... So the problem persists: I need a way for the script to bypass an array that is passed to the form... Any thoughts Thanks again! David Last edited by ppgpilot; Mar 25th, 2006 at 02:14. |
|
#4
|
|||
|
|||
|
If I understand your problem correctly:
When you submit a for with empty file fields the PHP script will pick these up as file arrays with empty data ( Try:
Therefore you need to put a check into your loop to test weather a file has been submitted. The following code (modified version of the above) should achieve this:
|
![]() |
| Tags |
| easy, question, someone |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A REALLY easy question ...I hope! | monit0r | Website Planning | 4 | Feb 3rd, 2008 20:19 |
| easy question thankyou | perform300 | Starting Out | 10 | Nov 12th, 2007 07:58 |
| [SOLVED] easy question | perform300 | Starting Out | 9 | Oct 17th, 2007 07:31 |
| very silly and easy question | saltedm8 | Web Page Design | 2 | Aug 22nd, 2006 22:35 |
| An easy OR format question | ppgpilot | PHP Forum | 3 | Jul 22nd, 2006 20:54 |