Re: Copy of image -> smaller

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'd make a wild guess that the FTP stuff isn't working...

Your biggest mistake is a total lack of error-handling...




On Mon, May 15, 2006 2:03 am, Gustav Wiberg wrote:
> Hi there!
>
> When I upload a picture from a form, then I want to create a copy with
> a
> smaller image.
> For example: I upload a picture with dimensions 200x150 name 4.jpg. I
> also
> want a copy of this image but with the dimensions 100x75 pixels. I've
> tried
> this below, but I'm missing something I think... :-)
>
> I'm using PHP 4.x  (don't know exactly the vers.nr, but I can search
> for it
> if it is of importance)
>
> The code down below is a function for uploading a picture. The part I
> want
> help with is after the comment: //What should/could I do here?
>
> Best regards
> Gustav Wiberg
>
>
>
> <?php
> function uploadPic($idUpload, $picUpload, $addUpload, $copyFile,
> $toPath) {
>
>    //Upload chosen file to upload-map (
>    //
>    if (strlen($_FILES[$picUpload]['name'])>0)
>    {
>    //ECHO "yes! ID=$idUpload PIC=$picUpload ADD=$addUpload<br>";
>    $uploaddir = dirname($_FILES[$picUpload]['tmp_name']) . "/";
>
>    //Replace .jpeg to .jpg
>    //
>    $_FILES[$picUpload]['name'] =
> str_replace(".jpeg",".jpg",$_FILES[$picUpload]['name']);
>
>    //Get first 4 last characters of uploaded filename
>    //
>    $ble = strtolower(substr($_FILES[$picUpload]['name'], -4, 4));
>
>    //Move to path $toPath (followed by what to add after file (that is
> sent
> to this function)) and ext.)
>    //
>    $mfileAdd = $idUpload . $addUpload . $ble;
>
>    move_uploaded_file($_FILES[$picUpload]['tmp_name'], $toPath .
> $mfileAdd);
>
>
>    //echo "mfileAdd=$mfileAdd<br><br>";
>    //Set appropiate rights for file
>    //
>    //echo "FILE TO TEST=$mfileAdd";
>    chmod($toPath . $mfileAdd, intval('0755', 8));
>
>
>    //Copy this file to another file?
>    //
>    if (strlen($copyFile)>0) {
>    $mfile = $idUpload . $copyFile . $ble;
>    //echo "MFILE=$mfile";
>    copy($toPath . $mfileAdd, $toPath . $mfile);
>    chmod($toPath . $mfile, intval('0755', 8));
>    }
>
>
> //What should/could I do here?
> //
>
>             //Set new width and height
>             //
>            $new_width = 100;
>            $new_height = 200;
>            $tmp_image=imagecreatefromjpeg($toPath . $mfileAdd);
>            $width = imagesx($tmp_image);
>            $height = imagesy($tmp_image);
>            $new_image = imagecreatetruecolor($new_width,$new_height);
>             ImageCopyResized($new_image, $tmp_image,0,0,0,0,
> $new_width,
> $new_height, $width, $height);
>
>             //Grab new image
>             ob_start();
>             ImageJPEG($new_image);
>             $image_buffer = ob_get_contents();
>             ob_end_clean();
>             ImageDestroy($new_image);
>
>             //Create temporary file and write to it
>             $fp = tmpfile();
>             fwrite($fp, $image_buffer);
>             rewind($fp);
>
>             //Upload new image
>             $copyTo = 'http://www.ledins.se/test.jpg';
>             $conn_id = ftp_connect('<domain>');
>             ftp_login($conn_id,'<username for domain>','<password>');
>             ftp_fput($conn_id, $copyTo, $fp, FTP_BINARY);
>             fclose($fp);
>
>
>
>    //Return the filename created based on productID
>    //
>    return $mfileAdd;
>    }
>
>
>
> }
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux