Anyone know why i am getting this error?
And no thumbs get created, i think because i get no return from $upload_result
ERROR:
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"> <h4>A PHP Error was encountered</h4> <p>Severity: Warning</p> <p>Message: stream_copy_to_stream() expects parameter 2 to be resource, boolean given</p> <p>Filename: libraries/Ajax_image_upload.php</p> <p>Line Number: 23</p></div>
Code:
Image:
public function upload($listing_id)
{
$to_insert = array('listing_id' => $listing_id,'`order`' => now());
if( $this->db->insert('img_gallery_images', $to_insert) )
{
//use the insert id as the filename
$id = $this->db->insert_id();
$file_name = $id . '.jpg';
$path = 'uploads/gallery/main/'. $listing_id .'/'. $file_name;
//make sure the folders exist
if($this->create_folders($listing_id))
{
//do the upload
$upload_result = $this->ajax_image_upload->do_upload($path, array('image/jpeg','image/jpg') );
if($upload_result !== FALSE)
{
if($this->resize_images($listing_id, $file_name))
{
return $id;
}
}
}
}
//delete the db record if something goes wrong
$this->db->delete('img_gallery_images', array('id' => $file_name));
return FALSE;
}
Ajax Class:
class Ajax_image_upload
{
function do_upload($path, $mimes = '')
{
$input = fopen("php://input", "r");
$temp = tmpfile();
$real_size = stream_copy_to_stream($input,$temp);
fclose($input);
if( $real_size != $this->_get_size() )
{
return FALSE;
}
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
//is the mimes validation required?
if( is_array($mimes) )
{
//get info about the image
$image_info = getimagesize($path);
$file_info = pathinfo($path);
//standardize mimes
if($image_info['mime'] == 'image/pjpeg') $image_info['mime'] = 'image/jpeg';
if($image_info['mime'] == 'image/x-png') $image_info['mime'] = 'image/png';
//mimes to validate the extension against
$mime_list = array(
'bmp' => 'image/bmp',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
'tiff' => 'image/tiff',
'tif' => 'image/tiff'
);
//see if image mime is in the dev's allowed array
if( in_array($image_info['mime'], $mimes) )
{
//make sure the file extension matches the mime type
if( $mime_list[$file_info['extension']] == $image_info['mime'])
{
return array( 'mime' => $image_info['mime'],
'filename' => $file_info['filename'],
'extension' => $file_info['extension']
);
}
}
//it failed! get rid of it
unlink($path);
return FALSE;
}
//allow anything
return TRUE;
}
function _get_size()
{
if( isset($_SERVER["CONTENT_LENGTH"]) )
{
return (int)$_SERVER["CONTENT_LENGTH"];
}
else
{
throw new Exception('Getting content length is not supported.');
}
}
}