Jump to content

Recommended Posts

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 -

[code]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) [/code]

and then later down it shows

[code]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)
{ [/code]

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


TFH
Link to comment
https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/
Share on other sites

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

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

[/quote]

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


Thanks!!
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:

[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>");
}
[/code]

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
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...
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

[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);
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>");
}
[/code]

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
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!

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

[code]if( $PHOTO_Size == 0)
{
$photo_upload=FALSE;
}
[/code]

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
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.