Hi all,
I’m trying to create a function that neatly takes an image upload from my form and resizes as needed and then saves to a new permanent location. I referenced another thread in here by nbewley(imagecopyresized() question)
I can’t seem to get the path correctly defined as imagejpeg($dst, $upload_filename) , shows error “No such file or directory”. I can’t figure out what I’m doing wrong. Unless my use of the image functions here are the real issue. I haven’t done this before.
Here’s my function:
function img_process($imagedetails, $src_image, $upload_dir){
//$imagedetails - result of getimagesize($src_image) - this function called if image is jpg
//$src_image = $_FILES['userfile']['tmp_name']; - from form upload
//$upload_dir var_dump shows "/home/tacres01/public_www/w1_uploads/"
$width = $imagedetails[0];
$height = $imagedetails[1];
//This will be used to determine if the file needs to be made smaller
$max_dim = 600;
if ($width > $max_dim || $height > $max_dim){
//New dimensions are required and determined here
$ratio = $width/$height;
if ($ratio > 1){
$dst_width = $max_dim;
$dst_height = $max_dim/$ratio;
} else {
$dst_height = $max_dim;
$dst_width = $max_dim*$ratio;
}
} else {
$dst_width = $width;
$dst_height = $height;
}
//load old image and map to new
$src = imagecreatefromjpeg($src_image);
$dst = imagecreatetruecolor($dst_width, $dst_height);
imagecopyresized($dst,$src,0,0,0,0,$dst_width,$dst_height,$width,$height);
//generate unique name for new file
$now = time();
while(file_exists($upload_filename = $upload_dir . $now . '-' . $_FILES['userfile']['name'])) {
$now++;
}
//var_dump($upload_dir);
//var_dump($upload_filename);
//save new image
if(imagejpeg($dst, $upload_filename, 80)) {
echo 'Image Saved';
return true;
} else {
echo 'Not Saved';
return false;
}
}
And for further information I’ll show you guys how I’m trying to define the correct path in my config.inc.php file:
$config['app_dir'] = dirname(dirname(__FILE__)); // "/home/tacres01/public_www/w1fma"
$config['upload_dir'] = dirname($config['app_dir']) . '/w1_uploads/'; // "/home/tacres01/public_www/w1_uploads/"
The dir /w1_uploads/ does exist and has the correct permissions for writing set. It is one level above what I’ve defined as the ‘app_dir’
I really hope I’m just being very stupid and I’m missing something obvious.
Any help from you smart people will be very much appreciated.
Ta.