metroid Posted October 25, 2011 Share Posted October 25, 2011 Hi there, i want to remake a script that uploads a images in one folder to script that uploads images to folder that is equal with article id. Something like - main_folder/images/articles/$id/image.jpg ... But i don't understand how i can create it.. I don't understand how the script can know last id and move images to the folder. It's easy to add script that create folder but how the script can know latest id?.. Here is the code that process images. [it's from php fusion cms so maybe someone could not understand some things.] Thank you.. Maybe some one can give some advice how script can know latest id?. if (isset($_POST['save'])) { $error = ""; $news_subject = stripinput($_POST['news_subject']); $news_cat = isnum($_POST['news_cat']) ? $_POST['news_cat'] : "0"; if (isset($_FILES['news_image']) && is_uploaded_file($_FILES['news_image']['tmp_name'])) { $image = $_FILES['news_image']; $image_name = stripfilename(str_replace(" ", "_", strtolower(substr($image['name'], 0, strrpos($image['name'], "."))))); $image_ext = strtolower(strrchr($image['name'],".")); if ($image_ext == ".gif") { $filetype = 1; } elseif ($image_ext == ".jpg") { $filetype = 2; } elseif ($image_ext == ".png") { $filetype = 3; } else { $filetype = false; } if (!preg_match("/^[-0-9A-Z_\.\[\]]+$/i", $image_name)) { $error = 1; } elseif ($image['size'] > $settings['news_photo_max_b']){ $error = 2; } elseif (!$filetype) { $error = 3; } else { $image_t1 = image_exists(IMAGES_N_T, $image_name."_t1".$image_ext); $image_t2 = image_exists(IMAGES_N_T, $image_name."_t2".$image_ext); $image_full = image_exists(IMAGES_N, $image_name.$image_ext); move_uploaded_file($_FILES['news_image']['tmp_name'], IMAGES_N.$image_full); if (function_exists("chmod")) { chmod(IMAGES_N.$image_full, 0644); } $imagefile = @getimagesize(IMAGES_N.$image_full); if ($imagefile[0] > $settings['news_photo_max_w'] || $imagefile[1] > $settings['news_photo_max_h']) { $error = 4; unlink(IMAGES_N.$image_full); } else { createthumbnail($filetype, IMAGES_N.$image_full, IMAGES_N_T.$image_t1, $settings['news_photo_w'], $settings['news_photo_h']); if ($settings['news_thumb_ratio'] == 0) { createthumbnail($filetype, IMAGES_N.$image_full, IMAGES_N_T.$image_t2, $settings['news_thumb_w'], $settings['news_thumb_h']); } else { createsquarethumbnail($filetype, IMAGES_N.$image_full, IMAGES_N_T.$image_t2, $settings['news_thumb_w']); } } } if (!$error) { $news_image = $image_full; $news_image_t1 = $image_t1; $news_image_t2 = $image_t2; } else { $news_image = ""; $news_image_t1 = ""; $news_image_t2 = ""; } } else { $news_image = (isset($_POST['news_image']) ? $_POST['news_image'] : ""); $news_image_t1 = (isset($_POST['news_image_t1']) ? $_POST['news_image_t1'] : ""); $news_image_t2 = (isset($_POST['news_image_t2']) ? $_POST['news_image_t2'] : ""); } } Quote Link to comment https://forums.phpfreaks.com/topic/249794-image-uploading-by-folder-id/ Share on other sites More sharing options...
Drummin Posted October 25, 2011 Share Posted October 25, 2011 When you add your new article you can then do a quick query to get the last id. $getid = mysql_query("SELECT id FROM table ORDER BY id DESC limit 1"); WHILE($gtid = mysql_fetch_array($getid)) { $id=$gtid['id']; } Quote Link to comment https://forums.phpfreaks.com/topic/249794-image-uploading-by-folder-id/#findComment-1282169 Share on other sites More sharing options...
PaulRyan Posted October 25, 2011 Share Posted October 25, 2011 There is no need for the while() statement Drummin. // Do the query to get the last article ID $idQuery = mysql_query("SELECT `id` FROM `articles` ORDER BY `id` DESC LIMIT 1"); // Fetch the returned row $idFetch = mysql_fetch_assoc($idQuery); // Assign the last article ID number to the variable $lastID $lastID = $idFetch['id']; Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/249794-image-uploading-by-folder-id/#findComment-1282182 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.