graham23s Posted March 22, 2008 Share Posted March 22, 2008 Hi Guys, i have a page on site called images.php , the user goes to this page and i echo back the images the logged in user has, with a delete button besides them, when they inititially sign up i allow 1 image to be uploaded to be their main image, on this page i allow the user to delete this main image if they wish and upload a new main profile image IF the "Make this my main profile image" is checked <?php // images.php // include("inc/inc_search.php"); // deal with the submission // if(isset($_POST['submit'])) { // some vars for the image // $image_file_name = $_FILES['image']['name']; $image_file_size = $_FILES['image']['size']; $image_file_temp = $_FILES['image']['tmp_name']; $image_file_type = $_FILES['image']['type']; // main image // $main_image = $_POST['main_image']; // need a query to see if there is already a profile image // $q_img_profile = "SELECT `image_thumb` FROM `cmd_users` WHERE `id`='$var_logged_in_user_id'"; $r_img_profile = mysql_query($q_img_profile); // vars to test // $row = mysql_fetch_array($r_img_profile); // thumb var // $var_thumbnail = $row['image_thumb']; // MAIN IMAGE ALREADY UPLOADED // if($var_thumbnail != '') { standard_error("Error","You already have a main image uploaded, please delete the old one first."); } else { // NESTED IF // if(isset($main_image)) { // insert into the profile table // } else { // insert into the images table // } } // deal with what comes after ................................................................ // } // start grabbing the images // $q_images = "SELECT * FROM `cmd_users` WHERE `id`='$var_logged_in_user_id'"; $r_images = mysql_query($q_images); // put the details in an array // $r = mysql_fetch_array($r_images); // vars // $image_fullsize = $r['image']; $image_thumb = $r['image_thumb']; print("<form action='images.php' method='POST'>\n"); print("<table class='form_table' cellpadding='5' cellspacing='0' >\n"); print("<tr>\n"); print("<td colspan='2' align='left'><h1>Upload Images</h1></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class='form_style' align='left'><label><b>Upload Image:</b></label></td><td class='form_style' align='left'><input type='file' name='image' size='40'></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td class='form_style' align='left'><label><b>Make this my main profile image:</b></label></td><td class='form_style' align='left'><input type='checkbox' name='main_image'></td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td colspan='2' align='right'><input type='submit' name='submit' value='Upload' /></td>\n"); print("</tr>\n"); print("</table>\n"); print("</form>"); // display users images // print("<table style='border: 1px solid ;' width='95%' border='0' cellpadding='5' cellspacing='0' >\n"); print("<tr>\n"); print("<td class='header' align='center'>Your Main Profile Image</td><td class='header' align='center'>Action</td>\n"); print("</tr>\n"); print("<tr>\n"); print("<td align='center'><a href='ups/images/$image_fullsize' target='_blank'><img src='ups/thumbs/$image_thumb' border='0'></a></td><td align='center'><a href='images.php?action=deleteimage'>Delete</a></td>\n"); print("</tr>\n"); print("</table>"); ?> this is what i have so far, if i check the table and the image_thumb isn't empty they already have a main image uploaded, i was then going to store the image into another table away from the main profile image, just wondering if i have over complicated the code also is it ok to nest if/else inside another if/else? thanks for any input guys Graham Link to comment https://forums.phpfreaks.com/topic/97384-uploading-images-logic/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.