Jump to content


Photo

if empty?


  • Please log in to reply
10 replies to this topic

#1 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 24 February 2006 - 08:20 PM

If need to do an if empty do this for a file upload.
Normally I use this

if ( ! empty( $a_row->performance ) ) {
bla bla bla
}

but it doesn't work, do you have to do it a different way because it a file upload?


Thanks James

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 24 February 2006 - 08:53 PM

I suppose you can try:

$thisvar = $a_row->performance;

if($thisvar == ''){echo"You can't upload air, b*tch.";}


PHP Ninja

#3 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 24 February 2006 - 09:17 PM

Sorry it's <input type="file" name="image" /><br>


This doesn't work

if ( ! empty( image ) ) {

#4 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 24 February 2006 - 09:26 PM

$img = $_POST['image'];

if($img == ''){echo"You didn't specify an image, you dirty wh*re";}

PHP Ninja

#5 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 24 February 2006 - 10:01 PM

Also:

if(!isset($image)){echo"The variable is empty!";}

Hope that was of some use. :-)
PHP Ninja

#6 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 24 February 2006 - 10:16 PM

Thanks for the quick responce. I have just tried both of the and they don't work, i get the message all time.

#7 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 24 February 2006 - 11:16 PM

They should both work fine. Can you post an examplpe of how you are using the code? Are you "POST"ing the variables from an html form on another page?
PHP Ninja

#8 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 25 February 2006 - 09:27 PM

<?php
// if an image is uploaded
if(isset($_POST['submit']))
{


I put the code here



}else{
    echo '
    <form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">
       <input type="file" name="image" /><br>
        <input type="file" name="image1" /><br>
        <input type="submit" name="submit" value="upload and resize image" />
    </form>
';
}
?>

I need it to check if there is anything in 'image1'

#9 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 25 February 2006 - 09:31 PM

<?php
// if an image is uploaded
if(isset($_POST['submit'])) {

  if ($_FILES['image1']['size'] > 0) {
    do something...
  }

}
?>


#10 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 26 February 2006 - 07:56 AM

That works great thanks!!!!!!!!!!!!!!!!!!

#11 xcoderx

xcoderx
  • Members
  • PipPipPip
  • Advanced Member
  • 848 posts
  • Locationindia

Posted 08 November 2008 - 08:38 AM

make sure unwanted files don't get uploaded to your server through this form so make sure to add some blacklist files to be blocked




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users