bothwell Posted August 3, 2008 Share Posted August 3, 2008 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 More sharing options...
cooldude832 Posted August 3, 2008 Share Posted August 3, 2008 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. Link to comment https://forums.phpfreaks.com/topic/117978-gd-imagejpeg-issues/#findComment-606941 Share on other sites More sharing options...
ignace Posted August 3, 2008 Share Posted August 3, 2008 // 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 More sharing options...
bothwell Posted August 3, 2008 Author Share Posted August 3, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.