Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/190020-image-upload-if-else-help/
Share on other sites

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"; } 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.