Tips Tricks Tutorials

WEB-NES-BAY

Learn Tips and tricks on Linux, Hacking, linux, PHP, Perl, Web, Hardware

bookmark bookmark
WEBNESBAY On September - 6 - 2009

Well, for this task there are many ways of realizing it, many scripts and libraries that they can do, and this is another way in which this can be accomplished in a simple manner and without disheveled, for this I am taking 2 classes of PEAR are HTTP_Upload and the other is Image_Transform basically this is what we need to go and make our thumbnail in a simple manner as discussed below.

For this also I forgot we have to be installed for php gd module is php_gd if we utilzar the GD library to do this (in my case that is what we use, but as the summer we also can use other libraries not necessarily this one).

Good start making a small form to upload your file, I will not do all the HTML will emphasize only the points needed, which may be obvious but sometimes those little details that you overlook one, or there days when you really not rise with the right foot (could also be because left-handed: p) and that day no one comes out, so for that you can always check the website for tips you can save the day: D.

The only detail to take care is that the form must have the property enctype = “multipart / form-data” and also our input file type should be type = “file” as we shall see in this small example,

form action="subir.php" method="post" enctype="multipart/form-data"
input name="userimage" type="file"
/form

Sorry for not mentioning the entire code with opening and closing tags. continuing the theme because we have our simple form let’s look at the side of php. only 2 classes need to include the above and are ready.

require_once "HTTP/Upload.php";
require_once "Image/Transform.php";

/* UPLOAD IMAGES */
/ * Do the Images Upload * /

$upload = new HTTP_Upload(”en”); / / Here we create our object so that it can climb and get as parameter the language in which we want to return errors. / / I will put it in english
$image = $upload->getFiles(”userimage”); / / here we get the filesystems uploaded in this case as our input is called that name userimage place and ready.
$ ImageObject = & Image_Transform:: factory ( ‘GD’), / / also create our object to manipulate the image once this up, as he had said prior to this utilizare GD

$ image_directory = “. / images /”; / / to this directory to upload the image.
if ($ image-> isValid ()) / / here check if the object userimage received information is valid and has
{ (
$ moved = $ image-> moveTo ($ image_directory. “/ tmp”); / / here this function upload the file to the server and moves it to the directory that tells
if (PEAR::isError($moved))
{ (
/ / “ERROR up the image” could check if Subri, if I throw a PEAR ERROR.
print_r ($ moved);
}else{ ) else (

/ * We get here the image is in the Server and we can start manipulating* /
$userimages = $image->getProp(); / / this meted siver us to get all the properties of the image, image type as that is, your name, extension and others.
$result = $imageObject->load($image_directory.”/tmp”.$userimages['name']); / / so the burden with the name that had been placed
if (PEAR::isError($result))
{ (
echo “ERROR THUMBNAIL”;
}else{ ) else (
$imageObject->resize(125,125); / / If not, it overrides what is the size you want for it rezisee (my nice word)
$imageObject->save($image_directory.$_POST['maindata']['idlisting'].”.gif”,”gif”,100); / / and recorded it again, once here take the opportunity to make
/ / A gif image that we do know is the 3rd parameter can be converted to jpg, png, etc …
/ / And the last parameter tells the quality we want in the image, these last 2 parameters are optional and are not
necesarios necessary
/* END Thumbnail */ / * END * Thumbnail /

} )

} )
} )

/ * END UPLOAD IMAGES * /

So that was it really update this post later so they can go down as a class that implements this and an example Pequeni so they can download and I hope it serves them, anything to take your questions here, and I will answer the soon as possible. In order to manipulate the image must first be uploaded to the server may not otherwise do nothing.

Related posts:

  1. Creating graphs and charts in PHP
  2. Creating IM Bot using PHP
Categories: PHP

Leave a Reply