johnnyboy16 Posted March 8, 2010 Share Posted March 8, 2010 Hey guys. I'm pretty new to programming, so please bare with me...I'm stuck right now.... I have a function that allows users to select images from a drop down. If the user wants to upload a new photo they can select that option from the drop down as well. The issue I'm having is that the portion of the script for the new image does not seem to work. (meaning it will not show up when you select "new image") I can't figure out, it was working for a little while earlier. Please help!!!! GET FUNCTION <table class="f_input"> <tr> <td class='f_label' style='width: 122px;'> My photo </td> <td> <?php $q = "Select ImageID, Name, Ext from `".IMAGES_TABLE."` Where UserID = '".$this->userid."' ORDER BY Name"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); echo "<select name='imageid' style=' width: 150px; padding: 2px; onchange='e_add_image();'"; if(!empty($this->inputs_errors['venue'])){echo "style='border: 1px solid #cc3300;'";} echo "/>"; echo "<option value='default'>--John's Default--</option>"; echo "<option value='new'>--New Image--</option>"; if(mysql_num_rows($r) >0){ while($row = mysql_fetch_assoc($r)){ echo "<option value='".$row['ImageID']."' "; if($this->inputs['imageid'] == $row['ImageID']){ echo "selected='selected' "; } echo ">".$row['Name']."</option>\\n"; $images[$row['ImageID']] = $row['Ext']; } echo "<script type='text/javascript'>"; echo "var images=new Array();"; foreach($images as $key=>$value){ echo "images[".$key."] = '".$value."';"; } echo "</script>"; } ?> </td> </tr> </table> <table class='f_input' id='a_e_newimage' style='display:none;'> <tr> <td class='f_label' style='width: 150px;'> New image name </td> <td> <input style='width: 190px; height: 18px;' type='text' name='new_image_name' value=""/> </td> </tr> <tr> <td class='f_label' style='width: 150px;'> Upload new photo </td> <td> <input type='file' name='image' style='height: 25px; border: none;' /> </td> </tr> </table> POST FUNCTON if($inputs['imageid'] == "new"){ $q = "Select ImageID from `".IMAGES_TABLE."` Where Name = '".$inputs['new_image_name']."' and UserID = '".$this->userid."'"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ $errors['new_image_name'] = "You have already uploaded an image with this name."; } else{ $update = 1; if($_FILES['image']['error'] != '0'){ $errors['image'] = "An unknown error occurred while your image was uploaded"; $update = 0; } if($_FILES['image']['size'] > MAX_IMAGE_SIZE){ $errors['image'] = "The image file that you uploaded was too large."; $update = 0; } $i_dat = getimagesize($_FILES['image']['tmp_name']); $i_types = array("image/jpeg","image/png","image/gif"); if(!in_array($i_dat['mime'],$i_types)){ $errors['image'] = "The image must be a jpeg, gif or png."; $update = 0; } if($update == 1){ $q = "INSERT INTO `".IMAGES_TABLE."` (UserID, Name) VALUES('".$this->userid."', '".$inputs['new_image_name']."')"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); $imgid = mysql_insert_id(); $inputs['imageid'] = $imgid; $width = $i_dat[0]; $width_max = 250; $height = $i_dat[1]; $height_max = 250; $tmp_name = $this->userid."_".date("U").".txt"; $tmp_pos = UPLOADS.$tmp_name; move_uploaded_file($_FILES['image']['tmp_name'],$tmp_pos); image_upload($tmp_name,$imgid); } } } else{ $q = "Select ImageID from `".IMAGES_TABLE."` Where UserID = '".$this->userid."' and ImageID = '".$inputs['imageid']."' LIMIT 1"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); if(mysql_num_rows($r) >0){ } else{ $q = "Select ImageID from `".EVENTS_CAT_TABLE."` Where ECatID = '".input_clean($inputs['cat'])."'"; $r = mysql_query($q) or die(mysql_error()."<br /><br />".$q); $row = mysql_fetch_assoc($r); $inputs['imageid'] = $row['ImageID']; } } Thank you in advance Link to comment https://forums.phpfreaks.com/topic/194562-image-upload-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.