Jump to content

image upload / if else help ..


imarockstar

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.