Rommeo Posted January 7, 2012 Share Posted January 7, 2012 I m using "empty" and "isset" for the textbox and textarea values to check if they were sent. For files, what should I use ? ( I tried to use empty and isset, and they did not give me the correct answer ) Quote Link to comment https://forums.phpfreaks.com/topic/254545-which-function-to-use-here/ Share on other sites More sharing options...
Pikachu2000 Posted January 7, 2012 Share Posted January 7, 2012 What did you use exactly, and how did you use it? Quote Link to comment https://forums.phpfreaks.com/topic/254545-which-function-to-use-here/#findComment-1305273 Share on other sites More sharing options...
Rommeo Posted January 7, 2012 Author Share Posted January 7, 2012 <?php $valueempty = empty($_FILES['image']) if($valueempty) { // code here } // and I have used like this seperately : $valueisset = isset($_FILES['image']); if($valueisset) { // code here } // did not send any file via form print "A:".$valueempty print "B:".$valueisset ?> output : A : B : 1 ( isset seems correct, but even I send file it gives me 1 ) Quote Link to comment https://forums.phpfreaks.com/topic/254545-which-function-to-use-here/#findComment-1305283 Share on other sites More sharing options...
Pikachu2000 Posted January 7, 2012 Share Posted January 7, 2012 You're assigning the result of empty() to $valueempty. empty returns a boolean value of TRUE or FALSE, so when you try to echo it, you will get either 1 or nothing at all. Same goes for isset. Quote Link to comment https://forums.phpfreaks.com/topic/254545-which-function-to-use-here/#findComment-1305287 Share on other sites More sharing options...
Rommeo Posted January 7, 2012 Author Share Posted January 7, 2012 You're assigning the result of empty() to $valueempty. empty returns a boolean value of TRUE or FALSE, so when you try to echo it, you will get either 1 or nothing at all. Same goes for isset. I have noticed it, so which function should I use to check if file was sent ? Quote Link to comment https://forums.phpfreaks.com/topic/254545-which-function-to-use-here/#findComment-1305289 Share on other sites More sharing options...
Pikachu2000 Posted January 7, 2012 Share Posted January 7, 2012 You should start out by checking to make sure there were no errors with it, by checking the value of $_FILES['image']['error']. There's a section in the manual on handling file uploads, and there is a section within that regarding upload errors. Reading through those would probably answer most of your questions. Quote Link to comment https://forums.phpfreaks.com/topic/254545-which-function-to-use-here/#findComment-1305291 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.