echo $type before going into the switch. I'm expecting this to not match the cases.
Image Upload/Resize/Create Thumbnail
It gave me a 2 when I echoed $type
I also echoed the $photo_moved and $thumb_moved variables above (after the move_uploaded_files) and got a 1 back if that helps troubleshooting at all.
within this if:
if ($photo_moved && $thumb_moved)
what do you get if you echo the $photo_original and $thumb_original vars?
also try doing a print_r($_FILES) there, as well as echoing the DEFINES PHOTO_DIR and THUMB_DIR
the 1 most likely represents a TRUE boolean which is acquired somewhere through a function return.
C:/wamp/www/test/photos/C:/wamp/www/test/photos/thumbs/Array ( [image] => Array ( [name] => _Ferrari-458-Italia-1-lg.jpg [type] => image/pjpeg [tmp_name] => C:\wamp\tmp\php232D.tmp [error] => 0 [size] => 193609 ) )
This is what I get when I type"
echo PHOTO_DIR;
echo THUMB_DIR;
print_r($_FILES);
When I only echo the move_uploaded_file for $thumb_moved I get no value at all. There should be a 1 in there just like when I echoed $photo_moved
ok the vars seem fine. Ferrari rocks.
it is weird though that you don't get the 1 as you said. if you don't get anything, it's bool false, which does not echo a 0 but echoes nothing. that would mean the function would have returned false.
however, this should have given an error message.
if you put the echoes in the IF statement, then we should be fine, as the IF validates both vars.
So within that same if, what do you get when you echo the $photo_original and $thumb_original vars?
I keep getting a parse error, where exactly should I put the echo statements? Yes, I am a die hard Ferrari fan. It is my life goal to own one. You should check out www.ferrarichat.com
I would place the echoes here:
if ($photo_moved && $thumb_moved)
{
$result = $_FILES['image']['name'].' successfully uploaded; ';
$photo_original = PHOTO_DIR.$_FILES['image']['name'];
$thumb_original = THUMB_DIR.$_FILES['image']['name'];
echo $photo_original.'<br>'.$thumb_original;
}
I didn't get anything back, just the usual errors.
very well. now try this:
var_dump($photo_moved);
var_dump($thumb_moved);
if ($photo_moved && $thumb_moved)
{
$result = $_FILES['image']['name'].' successfully uploaded; ';
$photo_original = PHOTO_DIR.$_FILES['image']['name'];
$thumb_original = THUMB_DIR.$_FILES['image']['name'];
}
I got: bool(true) bool(false) along with the following usual errors:
Notice: Undefined variable: photo_original in C:\wamp\www\test\addphoto.php on line 144
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename cannot be empty in C:\wamp\www\test\addphoto.php on line 144
Notice: Undefined variable: thumb_original in C:\wamp\www\test\addphoto.php on line 145
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename cannot be empty in C:\wamp\www\test\addphoto.php on line 145
Problem copying original photo.
ok that tells us there is indeed an issue with the thumb. I guess you said that before somewhere? not sure though.
can you confirm that the thumb dir is available for writing, and exists?
Yes, the thumbs directory exists and is writable. I've been analyzing this code and am seriously stunned that I cannot figure it out. It's like it doesn't want to create that variable ($thumb_moved) for some reason.
oh I know I know I know
possibly
you're doing move_uploaded_file, twice! you're trying to copy it this way, but that doesn't work, because after the first move, there is no uploaded file.
instead, copy the file to the thumb location after the first move_uploaded_file.
There is some light at the end of the tunnel, lol. Just one question...what code would I use and where would I put it?
try this:
$photo_moved = move_uploaded_file($original, PHOTO_DIR.$_FILES['image']['name']);
$thumb_moved = copy(PHOTO_DIR.$_FILES['image']['name'], THUMB_DIR.$_FILES['image']['name']);
if ($photo_moved && $thumb_moved)
{
$result = $_FILES['image']['name'].' successfully uploaded; ';
$photo_original = PHOTO_DIR.$_FILES['image']['name'];
$thumb_original = THUMB_DIR.$_FILES['image']['name'];
}
else
{
$result = 'Problem uploading '.$_FILES['image']['name'].'; ';
}
might actually be easier than I thought. :p
OK, here is what I got:
Notice: Undefined variable: ratio in C:\wamp\www\test\addphoto.php on line 160
Notice: Undefined variable: ratio in C:\wamp\www\test\addphoto.php on line 161
Notice: Undefined variable: ratio in C:\wamp\www\test\addphoto.php on line 164
Notice: Undefined variable: ratio in C:\wamp\www\test\addphoto.php on line 165
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\test\addphoto.php on line 168
Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\wamp\www\test\addphoto.php on line 171
Notice: Undefined variable: source in C:\wamp\www\test\addphoto.php on line 174
Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\wamp\www\test\addphoto.php on line 174
Notice: Undefined variable: source in C:\wamp\www\test\addphoto.php on line 177
Warning: imagecopyresampled() expects parameter 1 to be resource, boolean given in C:\wamp\www\test\addphoto.php on line 177
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in C:\wamp\www\test\addphoto.php on line 199
Warning: imagejpeg() expects parameter 1 to be resource, boolean given in C:\wamp\www\test\addphoto.php on line 200
Warning: imagedestroy() expects parameter 1 to be resource, boolean given in C:\wamp\www\test\addphoto.php on line 230
Warning: imagedestroy() expects parameter 1 to be resource, boolean given in C:\wamp\www\test\addphoto.php on line 231
_Ferrari-458-Italia-1-lg.jpg successfully uploaded; Problem creating thumbnail
Here is what happened... It uploaded both images in their respective folders but did nothing to resize them, and all the errors as you can see above.
OK the issue is now the missing $ratio var. I see you used $thumb_ratio as well as $photo_ratio. Quite possibly you mean those. The main issue is fixed though, from now on it's basically cleaning the code.