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

Link to comment
Share on other sites

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.
?>

 

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.