Jump to content


Photo

If then else function help


  • Please log in to reply
10 replies to this topic

#1 tfh

tfh
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 June 2006 - 06:11 AM

Hi All,

I am new to PHP and am currently working on a php form. I have had some help creating the form with a php form creation program, however it is not doing everything I require.

The form has several text fields, date fields and two upload fields. One upload field is for documents and the other for photos. Each goes to its own folder on the webserver.

The upload fields are in the middle of the script, photo first and then the document field. The problem I have is that sometimes there will only be a photo uploaded, other times only a document and then probably more than not neither type of file will be uploaded with the rest of the information. I would like to he able to tell the script If the file size is 0 then goto the next function, not DIE, which is what it does now...

I just dont understand the if the else statements enough yet. I have been searching this site, google, and several other sources (even took off to the local book store and read through some books), so I hope someone here can spell it out in english ;) [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Can anyone help me out?

Here is a sample of the code as it is now -

if( $PHOTO_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid photo (Must be in .jpg or .gif format and less than 100K in size.)</font></p>");
}
if( $PHOTO_Size >100000)

and then later down it shows

if( $ARTICLE_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid article (must be less than 500K in size)</font></p>");
}
if( $ARTICLE_Size >500000)
{

Thanks! [img src=\"style_emoticons/[#EMO_DIR#]/wink.gif\" style=\"vertical-align:middle\" emoid=\":wink:\" border=\"0\" alt=\"wink.gif\" /]


TFH

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 04 June 2006 - 12:54 PM

Well the best way of doing it (in my opinion) is something like this:

if($size != 0)
{
//upload here
};

The script will continue to run anyway:
If the img size is larger than 0- it will upload and then contunue.
If not- just skip upload part and continue.

Orio.
Think you're smarty?

(Gone until 20 to November)

#3 tfh

tfh
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 04 June 2006 - 04:41 PM

[!--quoteo(post=379859:date=Jun 4 2006, 07:54 AM:name=Orio)--][div class=\'quotetop\']QUOTE(Orio @ Jun 4 2006, 07:54 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Well the best way of doing it (in my opinion) is something like this:

if($size != 0)
{
//upload here
};

[/quote]

Ok so after the IF statement
anything inside of { and } is the function, and the ';' means else or next?


Thanks!!

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 04 June 2006 - 04:43 PM

Do you want to post the script and me or someone else will change to fit your needs?

Orio.
Think you're smarty?

(Gone until 20 to November)

#5 tfh

tfh
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 05 June 2006 - 04:46 AM

I sent that part of the code to you in a PM - I hope that is ok - now that I did it...
I was only able to send the part of code that I need to edit - the pm would not let me send the whole works. ;)

Thanks

TFH

#6 tfh

tfh
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 June 2006 - 07:07 PM

Hi All,

Orio has been helping me via PM but it seems we are stuck.

I am getting an error on what is line 91 of my script. Line 91 is noted below with "<--- THIS IS LINE 91."

Here is the code:

//Photo Validation
$photo_upload=TRUE;

if( $PHOTO_Size == 0)
{
$photo_upload=FALSE;
}
if( $PHOTO_Size >100000000)
{
//delete file 
unlink($PHOTO_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid photo (Must be in .jpg or .gif format and less than 100K in size.)</font></p>");
}
if( $PHOTO_Mime_Type != "image/gif" AND $PHOTO_Mime_Type != "image/pjpeg" AND $PHOTO_Mime_Type != "image/jpeg" )
{
unlink($PHOTO_Temp);     <------THIS IS LINE 91 WHERE THE ERROR OCCURS***
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid photo (Must be in .jpg or .gif format and less than 100K in size.)</font></p>");
}

Here is the error I get when trying to run the script from the form --
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Warning: unlink(): No such file or directory in /home/server/public_html/folder/FORM.php on line 91

Please enter a valid photo (Must be in .jpg or .gif format and less than 100K in size.)
[/quote]

Any help would be great! Does the unlink thing even need fixing?

TFH

#7 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 07:14 PM

Use:
@unlink($PHOTO_Temp);

That will suppress the error you would get if the file doesn't exist.

Info: PHP Manual


#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 06 June 2006 - 07:16 PM

well you have an if () before that that unlinks it. maybe it met that condition and now this new condition is being met as well, only it's already been unlinked, and therefore the file doesn't exist?

i suggest combining your two if statements. you already combined your error statements...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 tfh

tfh
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 06 June 2006 - 07:30 PM

Wow thanks for the super fast replies!!!

Ober - I added the '@' and that fixed the line 91 error, however I still get the error message "Please enter a valid photo (Must be in .jpg or .gif format and less than 100K in size.)
" - Question though, what did the @ do to fix the error?

Here is how the code looks now


//Photo Validation
$photo_upload=TRUE;

if( $PHOTO_Size == 0)
{
$photo_upload=FALSE;
}
if( $PHOTO_Size >100000000)
{
//delete file 
@unlink($PHOTO_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid photo (Must be 

in .jpg or .gif format and less than 100K in size.)</font></p>");
}
if( $PHOTO_Mime_Type != "image/gif" AND $PHOTO_Mime_Type != "image/pjpeg" AND $PHOTO_Mime_Type != 

"image/jpeg" )
{
@unlink($PHOTO_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid photo (Must be 

in .jpg or .gif format and less than 100K in size.)</font></p>");
}

I am now getting this error [quote]Please enter a valid photo (Must be in .jpg or .gif format and less than 100K in size.)
[quote]

I get this error if I put in a .jpg or .gif under 100k, and when I leave them blank..... Im sure I said it in the message earlier, but I am wanting the script to skip the upload if there is no image or article.. and of course upload them if they are there and less than 100k for photo and 500k for article...

Thanks Again All - I need to know where to donate to this project as well - so much help in such real time! :) Thanks Again!!!

TFH

#10 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 06 June 2006 - 07:40 PM

The @ symbol will stop error messages from being sent to the browser.

And there is a thread here: [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=45685\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?showtopic=45685[/a] where you can donate to the site if you wish. Any and all donations are appreciated and go directly to helping with the bandwidth costs the site deals with!


Info: PHP Manual


#11 tfh

tfh
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 08 June 2006 - 02:32 AM

Isnt there anyone here that can figure help me figure out what the problem is? It is still ignoring the statement

if( $PHOTO_Size == 0)
{
$photo_upload=FALSE;
}

I dont see a problem with it - as I see it - it should skip the TRUE statement if the file = 0 and not die...

Please help...



Thanks

TFH




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users