Jump to content

Creating thumbs


Woodburn2006

Recommended Posts

i have a script that creates thumbnails from an uploaded img. this script works when i have the script on a page in a folder and the imgs being created in subfolders within the root folder that the php file is stored.

 

the problem i am having is that when i want to create the images and put them into a different folder on a lower level of the site map it just creates black images.

 

for example: the structure of my site map is;

 

ROOT FOLDER

- img

-- gallery

--- lrg (where the lrg version of the img is)

--- temp (where the temporary img is uploaded)

--- thumbs (where the thumb will be saved)

 

- content

 

- cp

-- images (where add.php is)

 

what i want to do is have the function beingcalled in add.php and for the files to be stored in the lrg and thumbs folders within the img folder. i have tried using paths etc to do this but it still does not work.

 

here is the function:

function createthumb($name,$filename,$new_w,$new_h)
{
	$system=explode('.',$name); // split filename either side of the '.'
	if (preg_match('/jpg|jpeg/',$system[1])){ // if extension is jpg or jpeg
		$src_img=imagecreatefromjpeg($name); // create a copy of the image in jpg
	}
	if (preg_match('/png/',$system[1])){ // if extension is png
		$src_img=imagecreatefrompng($name); // create a copy of the image in png
	}
	$old_x=imageSX($src_img); // gets width of original image
	$old_y=imageSY($src_img); // gets height of original image
	if ($old_x > $old_y) { // if img is wider than high
		$thumb_w=$new_w; // sets width variable of new img
		$thumb_h=$old_y*($new_h/$old_x); // sets height variable by doing: height = original width * (100 / original height)
	}
	if ($old_x < $old_y) { // other way around from setting wider than high
		$thumb_w=$old_x*($new_w/$old_y);
		$thumb_h=$new_h;
	}
	if ($old_x == $old_y) { // if img is square sets variabls straight forwardly
		$thumb_w=$new_w;
		$thumb_h=$new_h;
	}
	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // creates image
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // copies into new image
	if (preg_match("/png/",$system[1])) // if old file extension is png
	{
		imagepng($dst_img,$filename); // extension of new image is png
	} else {
		imagejpeg($dst_img,$filename); // else extension of new image is jpeg or jpg
	}
	imagedestroy($dst_img); //destroys variable
	imagedestroy($src_img); 
}

 

here is add.php:

<?
$function = ((isset($_GET['function']))?($_GET['function'])''));
if($function=="add"){

	if ($_FILES['uploadedfile']['name'] !=""){

		$pic1=$_FILES['uploadedfile']['name'];
		$target_path = "/customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/img/gallery/temp/";
		$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
		if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
			$nm = '1';
			$new_img = "http://www.ontherocks.me.uk/img/gallery/temp/$pic1";
			$thumb = "/customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/img/gallery/thumbs/$pic1";
			createthumb($new_img,$thumb,100,100);
		}else{
			echo "There was an error uploading the file, please try again!";
		}
	}else{
		$nm = '0';
		echo "No New Picture Added!<br><br>";
	}

if ($nm=='1'){
	//if ($_SERVER['REQUEST_METHOD'] == "POST"){
	//	$sql  = " INSERT INTO gallery ";
		//$sql .= " (name, price, status, width, height, description, img) VALUES ";
		//$sql .= " ('$name', '$price', '$status', '$width', '$height', '$description', '$img') ";
		//$result = mysql_query($sql, $connection);
		//if (mysql_error()) { print "Database ERROR: " . mysql_error(); }



		echo "
			The File Has Been Added!
			";
	}


}else{

	echo"
		<div id='news_add'>
			<form id='news_new' method='post' action='/cp/index2.php?go=img_add&function=add' enctype='multipart/form-data'>
				<br /><strong>Add Image</strong><br /><br />
				<input name='uploadedfile' type='file' size='80%'>
				<label>
				<input type='submit' id='img_submit' value='Submit' class='submit'>
				</label>
				<br /><br />
			</form>
		</div>";

}
?>

 

hopefully you can see what i mean from these files.

 

if it helps then to get to the page, goto: http://www.ontherocks.me.uk/cp

user: lee

pass: ontherocks

 

thanks in advance

 

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.