Jump to content

Image uploading by folder id.


metroid

Recommended Posts

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'] : "");
}

		}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.