Jump to content

thumbnail code / saving image to different directories


hellonoko

Recommended Posts

I am trying to make the below image resizing code save to a different directory than the one the .php file is in.

 

I have tried a few things but without success. Any ideas?

 

 


<?php

//Name you want to save your file as
$file = 'original.jpg';

$save = 't_'.$file;

echo "Creating file: $save";

$size = 0.45;

// header('Content-type: image/jpeg') ;
list($width, $height) = getimagesize($file) ;

$modwidth = $width * $size;
$modheight = $height * $size;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;

imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

// Here we are saving the .jpg, you can make this gif or png if you want
//the file name is set above, and the quality is set to 100%

imagejpeg($tn, $save, 100) ;
?> 

 

Thanks,

Ian

did you try specifying the directory to save in relation to where the php file is?

<?php
$save = '../../thumbnails/t_'.$file; //back two directories and into the thumbnail directory
?>

whats the error that you get? is your new directory chmoded?

 

you might also want to try an absolute path:

<?php
$save = './thumbnails/t_'.$file; //into thumbnail directory that is located in the root of the website.
?>

 

This *might* help --> http://en.wikipedia.org/wiki/Path_(computing)

 

You want to use a relative path like mcastles said.

 

If the code is in /resize/ and you want to save thumbs in /resize/thumbs/, then

$save = './thumbs/t_'.$file;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.