imarockstar Posted January 27, 2010 Share Posted January 27, 2010 I am trying to upload an image .. but if someone does not select an image i need the script to do something else .. this is what i have .. if ($_POST['addband']) { if (isset ($_FILES['bandpik'])){ $imagename = $_FILES['bandpik']['name']; $source = $_FILES['bandpik']['tmp_name']; $target = "../bandpiks/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "../bandpiks/" . $imagepath; //This is the new file you saving $file = "../bandpiks/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 500; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; $save = "../bandpiks/sml_" . $imagepath; //This is the new file you saving $file = "../bandpiks/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 80; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; echo "Large image: <img src='../bandpiks/".$imagepath."'><br>"; echo "Thumbnail: <img src='../bandpiks/sml_".$imagepath."'>"; } else { echo "wooops"; } the actual image upload works great .. but if someone does not select an image from the form, the script still runs .... i thought i had fixed that with the if (isset ($_FILES['bandpik'])){ ... ut i was wrong .. any suggestions ? thanks Quote Link to comment https://forums.phpfreaks.com/topic/190020-image-upload-if-else-help/ Share on other sites More sharing options...
RussellReal Posted January 27, 2010 Share Posted January 27, 2010 is_uploaded_file Quote Link to comment https://forums.phpfreaks.com/topic/190020-image-upload-if-else-help/#findComment-1002553 Share on other sites More sharing options...
imarockstar Posted January 27, 2010 Author Share Posted January 27, 2010 does not seem to work ... even if i select an image .. it still passes the image upload .. if ($_POST['addband']) { if (is_uploaded_file ($_FILES['bandpik']['name'])){ $imagename = $_FILES['bandpik']['name']; $source = $_FILES['bandpik']['tmp_name']; $target = "../bandpiks/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "../bandpiks/" . $imagepath; //This is the new file you saving $file = "../bandpiks/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 150; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; $save = "../bandpiks/sml_" . $imagepath; //This is the new file you saving $file = "../bandpiks/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 80; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; echo "Large image: <img src='../bandpiks/".$imagepath."'><br>"; echo "Thumbnail: <img src='../bandpiks/sml_".$imagepath."'>"; } //else { $imagepath = 'g_no_pik_yet.png'; } else { echo "woops, no image"; } Quote Link to comment https://forums.phpfreaks.com/topic/190020-image-upload-if-else-help/#findComment-1002591 Share on other sites More sharing options...
RussellReal Posted January 27, 2010 Share Posted January 27, 2010 you'd want to apply it to $_FILES['bandpik']['tmp_name'] and.. if you mean STOP THE PHP FROM RUNNING IN GENERAL.. you can't, that would be javascript to actually check if the file input has any value. Quote Link to comment https://forums.phpfreaks.com/topic/190020-image-upload-if-else-help/#findComment-1002595 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.