Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.