View Full Version : UPload form doesn't copy images
StevenJ
Dec 13, 2009, 03:36 PM
Hi,
I am new to Mac. I have done been using the windows IIS development platform for years, but recently bought a mac book and I'm now a complete convert. I have moved my development across to the mac php/mysql and got all that working wonderfully well but my upload form doesn't work.
I am familiar with unix and I have checked permissions using the shell window and everyone had read/write/execute access in the image folder, but when I try the form and press the upload button, it just doesn't copy the image there.
Is there anything obvious that I could have missed?
Kind Regards
S :confused:
jaikob
Dec 13, 2009, 03:39 PM
You need to post your code.
Otherwise its a folder permissions problem.
You did use the move_uploaded_file() function right?
Use the full path to the images folder starting with root "/" dir.
StevenJ
Dec 28, 2009, 07:37 AM
I have checked the folder permissions, and every user has read/write access...
When the file uploads, it copies the image to the image root folder. From there is should resize the image, and then copy to a sub folder called thumbs, and resize it again. I also have the option of the image being available to a blog, and copy/resize the image a third time.
Now the image is being copied to the image root folder, but it is not being resized, nor copied to the two sub folders.....
This DOES work on my windows/apache/php development machine though :mad:
if ((($_FILES['myfile']['type']) != "image/jpeg" ) &&
(($_FILES['myfile']['type']) != "image/jpg") &&
(($_FILES['myfile']['type']) != "image/pjpeg") &&
(($_FILES['myfile']['type']) != "image/jpe" ))
{
$result = 0 ;
$message = $_FILES['myfile']['type'] . "<br />Wrong type of file" ;
} else {
if( $_FILES['myfile']['size'] == 0 || $_FILES['orig_file']['size'] > 25360000 ) {
$result = 0 ;
$message = $_FILES['myfile']['size'] . "File is either Zero size or too large" ;
} else {
if (((!is_dir($store_dir)) || (!is_dir($thumb_dir)) || (!is_dir($blog_dir)) ) ){
$result = 0 ;
$message = "Destination Specified is not a directory" ;
} else {
$target_path = $store_dir . $filename ;
if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
$result = 1;
$message = "<br />Filename " . $filename ;
// Max height and width
$max_width = $THUMB_IMAGE_WIDTH ;
$max_height = $THUMB_IMAGE_HEIGHT ;
$full_max_width = $MAIN_IMAGE_WIDTH ;
$full_max_height = $MAIN_IMAGE_HEIGHT ;
$blog_max_width = $BLOG_IMAGE_WIDTH ;
$blog_max_height = $BLOG_IMAGE_HEIGHT ;
$full = $store_dir . $filename ;
$blog = $blog_dir . $filename ;
$thumb = $thumb_dir . $filename ;
$size = GetImageSize($full); // Read the size
$width = $size[0];
$height = $size[1];
// Proportionally resize the image to the
// max sizes specified above
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
$full_x_ratio = $full_max_width / $width;
$full_y_ratio = $full_max_height / $height;
$blog_x_ratio = $blog_max_width / $width;
$blog_y_ratio = $blog_max_height / $height;
// if necessary resize the uploaded image so that
// the MAX dimension in either direction is not breached.
if( ($width <= $full_max_width) && ($height <= $full_max_height) )
{
$full_width = $width;
$full_height = $height;
}
elseif (($full_x_ratio * $height) < $full_max_height)
{
$full_height = ceil($full_x_ratio * $height);
$full_width = $full_max_width;
}
else
{
$full_width = ceil($full_y_ratio * $width);
$full_height = $full_max_height;
}
// Create the new image!
$src = imagecreatefromjpeg($full);
$dst = imagecreatetruecolor($full_width, $full_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $full_width, $full_height, $width, $height);
imagejpeg($dst, $store_dir . $filename, IMAGE_QUALITY);
// Destroy the images
// don't destroy the uploaded image until thumbnail has been created/ / ImageDestroy($src);
imagedestroy($dst);
// sort out the thumbnail images
if( ($width <= $max_width) && ($height <= $max_height) )
{
$tn_width = $width;
$tn_height = $height;
}
elseif (($x_ratio * $height) < $max_height)
{
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else
{
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
imagejpeg($dst, $thumb_dir . $filename, IMAGE_QUALITY);
imagedestroy($dst);
// sort out the blog images
if ($_POST['blog'] == 1) {
if( ($width <= $blog_max_width) && ($height <= $blog_max_height) )
{
$blog_width = $width;
$blog_height = $height;
}
elseif (($blog_x_ratio * $height) < $blog_max_height)
{
$blog_height = ceil($blog_x_ratio * $height);
$blog_width = $blog_max_width;
}
else
{
$blog_width = ceil($blog_y_ratio * $width);
$blog_height = $blog_max_height;
}
$dst = imagecreatetruecolor($blog_width, $blog_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $blog_width, $blog_height, $width, $height);
imagejpeg($dst, $blog_dir . $filename, IMAGE_QUALITY);
imagedestroy($dst);
}
imagedestroy($src);
}
}
}
}
angelwatt
Dec 28, 2009, 08:21 AM
imagejpeg($dst, $store_dir . $filename, IMAGE_QUALITY);
Is IMAGE_QUALITY ever defined? Is it a constant or a variable? If a variable, you're missing the $. This variable is used in other parts of the code as well.
StevenJ
Dec 28, 2009, 08:29 AM
it is defined. it is defined as a constant 80 in a include file where I have all my constants defined.
define('IMAGE_QUALITY', 80);
designguy79
Dec 29, 2009, 09:04 AM
I would remove the "@" on this line:
...clip... @move_uploaded_file ...clip...
You are basically suppressing the error handling routine which is keeping you from seeing what the error message is. What is the output with the "@" removed from that line?
StevenJ
Dec 30, 2009, 04:15 PM
I am certain I have highlighted the problem....
I don't have php_gd.dll included.
I have had a php holiday so to speak, and I think I need it enabled for the following functions, however, I don't know how to do it on a Mac! searhing for the php.ini is more difficult than a PC! I'll master this mac if it kills me, but can anyone advise where I might find the php ini and the php_gd.dll file?
imagecreatefromjpeg()
imagecreatetruecolor()
imagecopyresampled()
imagejpeg()
StevenJ
Dec 30, 2009, 05:02 PM
the problem is definitely that I have no php_gd2.dll loaded....
how do I do this? I am new to mac, and hence struggling.
I have edited the /etc/php.ini file and removed the ';' from the beginning of the line, restarted apache using the terminal - but no extensions show up in phpinfo().
furthermore, when I navigate to the
/usr/lib/php/extensions/no-debug-non-zts-20060613
directory, there are no dll's there :mad:
how do I enable php_gd2.dll ?
angelwatt
Dec 30, 2009, 06:20 PM
You have to install it (http://php.net/manual/en/book.image.php) if it's not there. If you're not running the server, ask the web host to get it installed.
StevenJ
Dec 30, 2009, 06:22 PM
on my host, it's there and my application works grand, it's just on my dev machine which is now a mac, not a PC that I can't get it to work!
Will look at the instructions you have provided for installation details....
designguy79
Dec 31, 2009, 09:43 AM
Have you tried MAMP (http://www.mamp.info/en/documentation/releases.html)? It comes with gd. I have found it much easier to manage Apache, MySQL, PHP and PhpMyAdmin using 1 package.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.