tommyda Posted November 14, 2009 Share Posted November 14, 2009 Im building an admin panel with an image upload function, but I have set it to only run the image upload script if the file field is set. For some reason the function is running even if it is not set, which is obviously giving me errors. I also created 2 radio buttons one next to an input field named "url" and the other next to the file field named "upload" I tried to change the upload function to only run when radio button "upload" is selected which also doesnt work and runs either way. The form code: <tr> <td valign="top">Image Url</td> <td><label> <input type="radio" name="imageupload" value="url"><input name="imageurl" type="text" id="slug" size="70" /> </label></td> </tr> <tr> <td valign="top">Image Upload</td> <td><label> <input type="radio" checked name="imageupload" value="upload"> <input name="new_image" type="file" id="new_image" size="60" /> </label></td> </tr> The Upload Function: <?php if ($_POST['imageupload']='upload' && isset($_FILES['new_image'])){ $imagename = $_FILES['new_image']['name']; $source = $_FILES['new_image']['tmp_name']; $target = "../images/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "../images/" . $imagepath; $file = "../images/" . $imagepath; list($width, $height) = getimagesize($file) ; $modwidth = 120; $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 = "../images/sml_" . $imagepath; $file = "../images/" . $imagepath; 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) ; $fullimagepath = $baseurl.'/images/'.$imagepath; }else { $fullimagepath = $_POST['imageurl']; }; ?> Any help would be much appreciated. Thanks for reading. Quote Link to comment Share on other sites More sharing options...
tommyda Posted November 14, 2009 Author Share Posted November 14, 2009 Its ok, Ive got it if ($_POST['imageupload']=='upload' && isset($_FILES['new_image'])){..... Quote Link to comment Share on other sites More sharing options...
rarebit Posted November 14, 2009 Share Posted November 14, 2009 Not fully looked into it, but: if ($_POST['imageupload']=='upload' && isset($_FILES['new_image'])){ Do you notice the difference? Quote Link to comment Share on other sites More sharing options...
tommyda Posted November 14, 2009 Author Share Posted November 14, 2009 Thanks rarebit, but I beat you to it. Quote Link to comment 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.