Jump to content

Recommended Posts

Caveat: I've never used GD before, so I have absolutely no idea what I'm doing.

 

Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\htdocs\admincp\test.php on line 30

 

The above always appears at the top of the page :)

 

The database record contains always contains "1." when I POST using this code:

 

      foreach ($_FILES as $file)
        {
          if ($file['error'] == UPLOAD_ERR_OK)
            {
              $jpg = imagejpeg ($file);
              
              $tmp_name = $jpg['tmp_name'];
              $name = $jpg['name'];
              $fileNameParts = explode( '.', $name );
              $target = "../images/properties/$name";
              while (file_exists($target))
              {
                $fileNameParts[0] .= "1";
                $name = $fileNameParts[0] . "." . $fileNameParts[1];
                $target = "../images/properties/$name";
              }
              move_uploaded_file($tmp_name, $target);

              $dbUpdate = "UPDATE images2 SET images='$name' WHERE image_id=$id";
              mysql_query($dbUpdate) or die(mysql_error());
            }	
        }

 

Line 30 is the $jpg = imagejpeg ($file); bit just underneath UPLOAD_ERR_OK

 

Like I say, I have no idea what I'm doing here. Any pointers as to what's expected of imagejpeg(); would be appreciated :)

 

Link to comment
https://forums.phpfreaks.com/topic/117978-gd-imagejpeg-issues/
Share on other sites

// multiple uploads are added in a numerical array as explained in the php manual 
// $_FILES = array
// (
//     'tmp_name' => array('msdj.tmp', 'msjsd.tmp', ...),
//     'name' => array('filename1', 'filename2', ...),
//     'size' => array('sizeFile1', 'sizeFile2', ..),
//     ...
// );
// 
// number of uploads
$num_uploads = sizeof((array) $_FILES['tmp_name']);

if (1 < $num_uploads) { // multiple uploads
   for ($i = 0; $i < $num_uploads; $i++) {
       if ($_FILES['error'][$i] == UPLOAD_ERR_OK) {
           // this upload is ok
       }
    }
}// Else single upload

Link to comment
https://forums.phpfreaks.com/topic/117978-gd-imagejpeg-issues/#findComment-606943
Share on other sites

look at how imagejpeg works you must have a valid image resource meaning you can't stream a file unless you first use imagejpegfromfile or imagejpegfromstring or what ever they are called.

 

Ah, gotcha. Couldn't figure out if it was ok to try and convert directly from POST or not - but seems not. Looks like it's all working now, so thanks!

Link to comment
https://forums.phpfreaks.com/topic/117978-gd-imagejpeg-issues/#findComment-606979
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.