Easy Question - for someone

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.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Mar 24th, 2006, 17:02
Junior Member
Join Date: Mar 2006
Location: usa
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Mar 24th, 2006, 22:32
Reputable Member
Join Date: Sep 2005
Location: Canada, BC
Age: 24
Posts: 239
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Easy Question - for someone

PHP: Select all

$n 1;
foreach(
$_FILES as $img)
{
  
$var 'img'.$n;
  ${
$var} = myimgupload($img);
  
$n++;

You will probaly need more security then this to prevent people from uploading 50 diffrent files etc. but this is basicly what you need.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Mar 25th, 2006, 00:19
Junior Member
Join Date: Mar 2006
Location: usa
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Mar 27th, 2006, 23:36
Junior Member
Join Date: Mar 2006
Location: Bradford, West Yorkshire, UK
Age: 25
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Re: Easy Question - for someone

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:
PHP: Select all

 print_r($_FILES); 

to see what's going on)

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:

PHP: Select all

if($_FILES)
{
  
$n 1;
  
  foreach(
$_FILES as $img)
    if(
$img["name"]) #The test to see if a file is submitted
    
{
      
$var 'img'.$n;
      ${
$var} = myimgupload($img);
      
$n++;
    }

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
easy, question, someone

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 02:28.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42