Remember me?... File upload and JPEG functions - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Remember me?... File upload and JPEG functions

NeakNeak Posts: 87Member
[code]function ImgUpload($title, $handle)
{
// Uh... This opens the file and counts the rows
$path = 'img/'. $handle .'_'. $title .'.jpg';
$thumb = 'img/'. $handle .'_'. $title .'_thumb.jpg';


// Move uploaded file
move_uploaded_file($_FILES['path']['tmp_name'], $path);


// Stuff for creating the thumbnail...
$imagecreated = ImageCreateFromJPEG($path);


// Set the values for some image croppage:
$arrayage = getimagesize($path);
$w = 40;
$h = 110;
$x = rand(1, $arrayage[0] - $w);
$y = rand(1, $arrayage[1] - $h);


// Create the temporary image file
$thumbImgResized = Imagecreatetruecolor($w, $h);

$originalimage = imagecreatefromjpeg($path);

imagecopyresized($thumbImgResized, $originalimage, 0, 0, $x, $y, $w, $h, $w, $h);

ImageJPEG($thumbImgResized, $thumb);

ImageDestroy($thumbImgResized);
}[/code]
Now that I've got that out, I'll tell you about it. ^^
It's an image uploading script for my site, but it's more than that! It also makes a jpeg of a random section of the picture.

That is, it would, if it ever got past the move_uploaded_file() function. For some reason, I always get an error that it can't do anything with the file, because it was never uploaded. In fact, I use my FTP program to see that it has indeed never been uploaded. I don't know why this isn't working, because everything seems in order to me.

Please help!

Comments

  • ManningManning Posts: 1,621Member
    : [code]function ImgUpload($title, $handle)
    : {
    : // Uh... This opens the file and counts the rows
    : $path = 'img/'. $handle .'_'. $title .'.jpg';
    : $thumb = 'img/'. $handle .'_'. $title .'_thumb.jpg';
    :
    :
    : // Move uploaded file
    : move_uploaded_file($_FILES['path']['tmp_name'], $path);
    :
    :
    : // Stuff for creating the thumbnail...
    : $imagecreated = ImageCreateFromJPEG($path);
    :
    :
    : // Set the values for some image croppage:
    : $arrayage = getimagesize($path);
    : $w = 40;
    : $h = 110;
    : $x = rand(1, $arrayage[0] - $w);
    : $y = rand(1, $arrayage[1] - $h);
    :
    :
    : // Create the temporary image file
    : $thumbImgResized = Imagecreatetruecolor($w, $h);
    :
    : $originalimage = imagecreatefromjpeg($path);
    :
    : imagecopyresized($thumbImgResized, $originalimage, 0, 0, $x, $y, $w, $h, $w, $h);
    :
    : ImageJPEG($thumbImgResized, $thumb);
    :
    : ImageDestroy($thumbImgResized);
    : }[/code]
    : Now that I've got that out, I'll tell you about it. ^^
    : It's an image uploading script for my site, but it's more than that! It also makes a jpeg of a random section of the picture.
    :
    : That is, it would, if it ever got past the move_uploaded_file() function. For some reason, I always get an error that it can't do anything with the file, because it was never uploaded. In fact, I use my FTP program to see that it has indeed never been uploaded. I don't know why this isn't working, because everything seems in order to me.


    Is your input named 'path', and did you set the form enctype properly? You've probably already been, but if not, this has an example:
    http://www.php.net/features.file-upload

    If you still have problems, you may want to check out $_FILES['path']['error'] to see if that sheds any light.
  • NeakNeak Posts: 87Member
    : Is your input named 'path', and did you set the form enctype properly? You've probably already been, but if not, this has an example:
    : http://www.php.net/features.file-upload
    :
    : If you still have problems, you may want to check out $_FILES['path']['error'] to see if that sheds any light.
    :

    Yes, my input is named path... But no, I didn't set the enctype properly. I completely forgot about this, even though I've run into a problem with it before! Thanks for reminding me, though.
Sign In or Register to comment.