slpctrl Posted May 6, 2008 Share Posted May 6, 2008 What I'm trying to do here, at least right now is to get this script to work, it's not doing what I want. I want, if the radio button for original size is selected to just save the image, and the others resize and then save. Not sure where my error is but it doesn't work. <?php echo('Upload images: <FORM ENCTYPE="multipart/form-data" ACTION="" METHOD="POST"> The file: <INPUT TYPE="file" NAME="image"><br> <b>Size of image:</b><br> <input type="radio" name="group1" value="Original" checked> Original<br> <input type="radio" name="group1" value="320x240"> 320x240<br> <input type="radio" name="group1" value="640x480"> 640x480<br> <b>Duration of upload:</b><br> <input type="radio" name="group2" value="day" checked> <b>One day</b><br> <input type="radio" name="group2" value="week"> <b>One week</b><br> <input type="radio" name="group2" value="month"> <b>One month</b><br> <input type="radio" name="group2" value="year"> <b>One year</b><br> <INPUT TYPE="submit" VALUE="Upload"> </FORM>'); //start upload function Function uploadimg($image = NULL) { $dir = "C:/wamp/www/images/"; $size = 1572864; if (is_null($image)) $image = $_FILES['image']; $imagetype = $_FILES['image']['type']; $imagesize = $_FILES['image']['size']; if (!isset($_FILES['image'])) exit; if (is_uploaded_file($_FILES['image']['tmp_name'])) { if ($imagesize>$size) { echo "The file is too big<br>"; exit; } if (($imagetype=="image/gif") || ($imagetype=="image/pjpeg") || ($imagetype=="image/jpeg") || ($imagetype=="image/png") || ($imagetype=="image/bmp")) { if (file_exists($dir . $image)) { echo "The file already exists<br>"; exit; } $res = copy($_FILES['image']['tmp_name'], $dir . $_FILES['image']['name']); if (!$res) { echo "upload failed!<br>n"; exit; } else { echo "upload sucessful<br>"; } echo "File Name: ".$_FILES['image']['name']."<br>"; echo "File Size: ".$_FILES['image']['size']." bytes<br>"; echo "File Type: ".$_FILES['image']['type']."<br>"; } else { echo "Wrong file type<br>"; exit; } } $my_file = $_FILES['image']['name']; } //end upload function //begin resize image function size($image, $w = 320, $h = 240) { header("Content-type: image/jpeg"); //retrieving the dimensions of image $x = @getimagesize($image); $sw = $x[0]; $sh = $x[1]; //setting the new drawn image as a $new variable based on it's file type $new = @ImageCreateFromJPEG($image) or $new = @ImageCreateFromPNG($image) or $new = @ImageCreateFromGIF($image) or $new = false; if(!$new) { readfile($new); } else { //Here are the GD library functions in use where we take the image, rescale, //get coordinates for watermark and all the other nice details and merge the //watermark in the center of the scaled image and return the new image $thumb = @ImageCreateTrueColor($w, $h); @ImageCopyResampled($thumb, $new, 0, 0, 0, 0, $w, $h, $sw, $sh); return $thumb; } } //end resize image $image = $_FILES['image']; if(isset($image) && $_POST['group1']=="Original") uploadimg($image); elseif(isset($image) && $_POST['group1']=="320x240") { $image = size($image); uploadimg($image); } elseif(isset($image) && $_POST['group1']=="640x480") { $image = size($image,640,480); uploadimg($image); } else die(); ?> Link to comment https://forums.phpfreaks.com/topic/104365-script-not-working/ Share on other sites More sharing options...
slpctrl Posted May 6, 2008 Author Share Posted May 6, 2008 How about this: I have an upload function (works) and the resize function, but it's not working with upload. How do I get it so that, if radio button Original is selected, it will remain original size, or resize for the other options? <?php echo('Upload images: <FORM ENCTYPE="multipart/form-data" ACTION="" METHOD="POST"> The file: <INPUT TYPE="file" NAME="image"><br> <b>Size of image:</b><br> <input type="radio" name="group1" value="Original" checked> Original<br> <input type="radio" name="group1" value="320x240"> 320x240<br> <input type="radio" name="group1" value="640x480"> 640x480<br> <INPUT TYPE="submit" VALUE="Upload"> </FORM>'); //start upload function Function uploadimg($image = NULL) { $dir = "images/"; $size = 1572864; if (is_null($image)) $image = $_FILES['image']; $imagetype = $_FILES['image']['type']; $imagesize = $_FILES['image']['size']; if (!isset($_FILES['image'])) exit; if (is_uploaded_file($_FILES['image']['tmp_name'])) { if ($imagesize>$size) { echo "The file is too big<br>"; exit; } if (($imagetype=="image/gif") || ($imagetype=="image/pjpeg") || ($imagetype=="image/jpeg") || ($imagetype=="image/png") || ($imagetype=="image/bmp")) { if (file_exists($dir . $image)) { echo "The file already exists<br>"; exit; } $res = copy($_FILES['image']['tmp_name'], $dir . $_FILES['image']['name']); if (!$res) { echo "upload failed!<br>n"; exit; } else { echo "upload sucessful<br>"; } echo "File Name: ".$_FILES['image']['name']."<br>"; echo "File Size: ".$_FILES['image']['size']." bytes<br>"; echo "File Type: ".$_FILES['image']['type']."<br>"; } else { echo "Wrong file type<br>"; exit; }} $my_file = $_FILES['image']['name'];} //end upload function //begin resize image function size($image, $w = 320, $h = 240) { $x = @getimagesize($image); $sw = $x[0]; $sh = $x[1]; $new = @ImageCreateFromJPEG($image) or $new = @ImageCreateFromPNG($image) or $new = @ImageCreateFromGIF($image) or $new = false; if(!$new) { readfile($new); } else { $thumb = @ImageCreateTrueColor($w, $h); @ImageCopyResampled($thumb, $new, 0, 0, 0, 0, $w, $h, $sw, $sh); return $thumb; } } //end resize image $image = $_FILES['image']; if(isset($image) && $_POST['group1'] == "Original") uploadimg($image); else die(); ?> Link to comment https://forums.phpfreaks.com/topic/104365-script-not-working/#findComment-534423 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.