orange08 Posted April 1, 2009 Share Posted April 1, 2009 hi, i have a file input type, how can i detect it as empty... if(empty($_POST['myfile'])) is not work. and i don't want to use empty($_FILES['myfile']['name']) because it'll indirectly upload it to my server, right? so, how can i detect this field is empty? Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/ Share on other sites More sharing options...
MadTechie Posted April 1, 2009 Share Posted April 1, 2009 if(empty($_POST['myfile'])) is not work. why? don't want to use empty($_FILES['myfile']['name']) because it'll indirectly upload it to my server, uploads what? Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-798442 Share on other sites More sharing options...
premiso Posted April 1, 2009 Share Posted April 1, 2009 and i don't want to use empty($_FILES['myfile']['name']) because it'll indirectly upload it to my server, right? so, how can i detect this field is empty? It uploads the file to your server once they push submit before the form is processed. It is simply stored in a "temp" directory until you move the file. So doing that test on the name is fine, you could even just do this: if (isset($_FILES['myfile'])) If that is set then they attempted to upload a file via that form/field. But yea, the file is already on the server. After the script is ran it is deleted, hence if you did not move the file before then it is wiped from the server. Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-798671 Share on other sites More sharing options...
orange08 Posted April 2, 2009 Author Share Posted April 2, 2009 and i don't want to use empty($_FILES['myfile']['name']) because it'll indirectly upload it to my server, right? so, how can i detect this field is empty? It uploads the file to your server once they push submit before the form is processed. It is simply stored in a "temp" directory until you move the file. So doing that test on the name is fine, you could even just do this: if (isset($_FILES['myfile'])) If that is set then they attempted to upload a file via that form/field. But yea, the file is already on the server. After the script is ran it is deleted, hence if you did not move the file before then it is wiped from the server. so, you meant that when i'm using if(empty($_FILES['myfile']['name']) ) then the file will be uploaded to server's temp directory... but, then if my code didn't take any action to the file, when the file will be removed from temp?...i'm not too understand... thanks! Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-799181 Share on other sites More sharing options...
MadTechie Posted April 2, 2009 Share Posted April 2, 2009 when you upload a file, if it fits in the limts set in php.ini (ie max_filesize etc) then the file goes to tmp,, this happens before your script starts ie 1. Form is submitted 2. files are uploaded 3. action script is tiggered 4. action script does the move from $_FILES['var']['tmp_name'] to path you choose So before you make the move you check to see if the uploaded file has a tmp name ($_FILES['var']['tmp_name']), if not then the file wasn't uploaded, of couse you can also check the error ie if($_FILES['var']['error'] == 0) { # upload is fine } i hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-799369 Share on other sites More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 I just use this: if ($_FILES['myfile']) { Works fine. Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-799372 Share on other sites More sharing options...
orange08 Posted April 2, 2009 Author Share Posted April 2, 2009 I just use this: if ($_FILES['myfile']) { Works fine. so, will $_FILES['myfile'] causing this file goes to temp? Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-799387 Share on other sites More sharing options...
MadTechie Posted April 2, 2009 Share Posted April 2, 2009 No.. it will not "cause" it, clicking the submit button does! 1. display form 2. submit form (file get uploaded here) 3. the form tiggers the (php) script in actions. So by the time the php has started the file is already in temp! when you upload a file, if it fits in the limts set in php.ini (ie max_filesize etc) then the file goes to tmp,, this happens before your script starts ie 1. Form is submitted 2. files are uploaded 3. action script is tiggered Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-799391 Share on other sites More sharing options...
orange08 Posted April 3, 2009 Author Share Posted April 3, 2009 No.. it will not "cause" it, clicking the submit button does! 1. display form 2. submit form (file get uploaded here) 3. the form tiggers the (php) script in actions. So by the time the php has started the file is already in temp! when you upload a file, if it fits in the limts set in php.ini (ie max_filesize etc) then the file goes to tmp,, this happens before your script starts ie 1. Form is submitted 2. files are uploaded 3. action script is tiggered thanks for the explanation. actually, my main purpose is not to upload the picture file, but only to check whether the file input field is selected with a picture. the upload process will be taken care by phpmailer later. so, my logic is something like this: if ($_FILES['myfile']) { //if the field is selected with picture calling phpmailer // it'll upload the file later }else{ error message to tell user to select a picture for file input field } so, my worries is if $_FILES['myfile'] will upload my file to temp, later my phpmailer upload again, then causing my server space being not enough...as i have 5 file input fields to check...and i'm not sure when will those files uploaded to temp will be removed... if many users perform the function(it's a submit form), then more and more server space will be utilized in this case? Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-800111 Share on other sites More sharing options...
MadTechie Posted April 3, 2009 Share Posted April 3, 2009 Okay.. i give.. can you show me the code that does the upload from phpmailer.. infact show me any phpcode that does an upload! Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-800124 Share on other sites More sharing options...
orange08 Posted April 4, 2009 Author Share Posted April 4, 2009 Okay.. i give.. can you show me the code that does the upload from phpmailer.. infact show me any phpcode that does an upload! oh, the one i used is phpmailer-fe which can be freely download online...in this case, i have to use several of it's file, but the main php file that manage the email is phpmailer-fe.php...actually, i tried before to find from the code, whether i can control the max file size that i can attached to the email, but don't know where to modify as i'm a newbie in php and programming...if you can help me, it's really great. but, i don't think i can paste all the code here because it's too long. or can i send you the file? Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-800950 Share on other sites More sharing options...
MadTechie Posted April 4, 2009 Share Posted April 4, 2009 okay lets see if we can clear this thread! #1 your starting question hi, i have a file input type, how can i detect it as empty... i don't want to use empty($_FILES['myfile']['name']) because it'll indirectly upload it to my server, right? WRONG! it doesn't see all my posts above! Summary (the files will be uploaded from the form and ONLY then php handles it..) so, how can i detect this field is empty? #2 you know, use empty($_FILES['myfile']['name']) actually, i tried before to find from the code, whether i can control the max file size that i can attached to the email, #3 phpmailer (yes i know it well) sends emails it has nothing todo with uploading files, attachments yes but not uploads #4 Max filesize of an attachment is based on the ISP's limit! not the email build! Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-800961 Share on other sites More sharing options...
orange08 Posted April 4, 2009 Author Share Posted April 4, 2009 okay lets see if we can clear this thread! #1 your starting question hi, i have a file input type, how can i detect it as empty... i don't want to use empty($_FILES['myfile']['name']) because it'll indirectly upload it to my server, right? WRONG! it doesn't see all my posts above! Summary (the files will be uploaded from the form and ONLY then php handles it..) so, how can i detect this field is empty? #2 you know, use empty($_FILES['myfile']['name']) actually, i tried before to find from the code, whether i can control the max file size that i can attached to the email, #3 phpmailer (yes i know it well) sends emails it has nothing todo with uploading files, attachments yes but not uploads #4 Max filesize of an attachment is based on the ISP's limit! not the email build! thanks for the reply! Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-800965 Share on other sites More sharing options...
orange08 Posted April 8, 2009 Author Share Posted April 8, 2009 as previously we mentioned that the file will be kept temporary in tmp in our hosting server... are we able to check this temp folder/directory in our hosting? seem that i can't find this directory in my hosting, normally where does it located? Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-804276 Share on other sites More sharing options...
MadTechie Posted April 8, 2009 Share Posted April 8, 2009 erm.. maybe echo tempnam(NULL, 'abc'); Quote Link to comment https://forums.phpfreaks.com/topic/152038-how-to-detect-its-empty/#findComment-804380 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.