tfh Posted June 4, 2006 Share Posted June 4, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/ Share on other sites More sharing options...
Orio Posted June 4, 2006 Share Posted June 4, 2006 Well the best way of doing it (in my opinion) is something like this:[code]if($size != 0){//upload here};[/code]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. Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-41687 Share on other sites More sharing options...
tfh Posted June 4, 2006 Author Share Posted June 4, 2006 [!--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 statementanything inside of { and } is the function, and the ';' means else or next?Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-41771 Share on other sites More sharing options...
Orio Posted June 4, 2006 Share Posted June 4, 2006 Do you want to post the script and me or someone else will change to fit your needs?Orio. Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-41772 Share on other sites More sharing options...
tfh Posted June 5, 2006 Author Share Posted June 5, 2006 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. ;)ThanksTFH Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-41947 Share on other sites More sharing options...
tfh Posted June 6, 2006 Author Share Posted June 6, 2006 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 91Please 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 Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-42541 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 Use:[code]@unlink($PHOTO_Temp); [/code]That will suppress the error you would get if the file doesn't exist. Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-42546 Share on other sites More sharing options...
.josh Posted June 6, 2006 Share Posted June 6, 2006 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... Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-42547 Share on other sites More sharing options...
tfh Posted June 6, 2006 Author Share Posted June 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-42556 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-42562 Share on other sites More sharing options...
tfh Posted June 8, 2006 Author Share Posted June 8, 2006 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...ThanksTFH Quote Link to comment https://forums.phpfreaks.com/topic/11136-if-then-else-function-help/#findComment-43045 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.