Jump to content

[SOLVED] Writing image to folder on server


Recommended Posts

hey there.  i've succesfuly created a thumbnail from an image that has be verified and copied to a folder on the server for later calling from a database.  I'm having trouble saving the new thumbnail file that has been created.  using move_uploaded_file($thumb, $thumbupload); does not work.  is there a GD function for writing an image to a directory?  the thumbnail as be created and just needs to be written now.  thanks

Link to comment
Share on other sites

You might get a more specific / suited answer if you provide some of the code you use to create the thumbnails. The creation of images (resizing ect.) is often very closely combined with saving them as an actual file on the server.

 

But imagejpeg(), imagegif() and imagepng() should do what you want:

 

http://dk2.php.net/manual/en/function.imagejpeg.php

Link to comment
Share on other sites

sorry bout that.  here's the code used to create the thumbnail.  only  jpegs and pngs are being uploaded and this has been verified already.

	
				$uploaddir = 'Orig/';
				$uploadfile = $uploaddir . basename($_FILES['imagefile']['name']);
				move_uploaded_file($_FILES['imagefile']['tmp_name'], $uploadfile);


				list($width, $height, $type, $attr) = getimagesize($uploadfile);


				if($filetype == "image/jpeg"){
					//header("Content-Type: image/jpeg");
					$Orig = imagecreatefromjpeg($uploadfile);
					$extension = ".jpeg";

				}
				else if($filetype == "image/png"){
					//header("Content-Type: image/png");
					$Orig = imagecreatefrompng($uploadfile);
					$extension = ".png";

				}
				else{
					echo "ERROR ERROR ERROR!!!!!!!!!!<BR>";
				}

				$thumb = imagecreatetruecolor(100,100);

				imagecopyresampled($thumb,$Orig,0,0,0,0,100,100,$width,$height);


				echo "variable thumb = ".$thumb;
				$uploadthumbdir = 'Thmb/';
				$thumbupload = $uploadthumbdir . basename($_FILES['imagefile']['name']);
				move_uploaded_file($thumb, $thumbupload);
				echo "finished uploading thumb image";
				echo "thumb = ".$thumb."<BR>";
				echo "thumbupload = ".$thumbupload."<BR>";


				echo "Original image = <img src=".$uploadfile." /><BR>";
				echo "Thumbnail = <img src=".$thumbupload." /><BR>";

 

excuse the abundance of echo's....i'm just using them for debugging purposes. thanks

Link to comment
Share on other sites

You simply add one of the functions I listed in my last reply after you have used imagecopyresampled:

 

<?php
//From your code
$thumb = imagecreatetruecolor(100,100);
imagecopyresampled($thumb,$Orig,0,0,0,0,100,100,$width,$height);

//Save the image as JPEG to a folder
imagejpeg($thumb, '/path/to/save/image/to/filename.jpg', 75);

//Save the image as PNG to a folder
imagepng($thumb, '/path/to/save/image/to/filename.png');

?>

 

Read up on the functions here:

 

http://php.net/manual/en/function.imagejpeg.php

http://php.net/manual/en/function.imagepng.php

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.