Hi,
I am having a problem with the following code, basically what i am trying to do is upload a number of images (There is no limit) and then create thumbnails for each image.
Now the issue doesn’t seem to occur when i upload small file sizes it’s when i try uploading larger images…
This is the code:
public function saveImageNamesFromIdeasPage(){
$query = "SELECT MAX(ID) as max FROM ideas";
$result = mysql_query($query);
$max = mysql_fetch_array($result);
$ideasID = $max['max'];
$root = $_SERVER['DOCUMENT_ROOT']. "/kidsintranet/public_html/ideasfiles/";
foreach($_FILES['image']['error'] as $key => $error){
$target_path = $root.basename($_FILES['image']['name'][$key]);
if(UPLOAD_ERR_OK === $error){
move_uploaded_file($_FILES['image']['tmp_name'][$key], $target_path);
mysql_query(
sprintf(
"INSERT INTO ideas_files (ideasID, ideas_files, deleted)VALUES(%d, '%s', false)",$ideasID,
mysql_real_escape_string($_FILES['image']['name'][$key])
)
);
}
Thumbnail::createthumb($_FILES['image']['name'][$key], $root."tn_".$_FILES['image']['name'][$key],114,109);
Thumbnail::createthumb($_FILES['image']['name'][$key], $root."main_".$_FILES['image']['name'][$key],800,600);
}
}
And finally the Thumbnail class createthumb method is shown below:
public function createThumb($name,$filename,$new_w,$new_h)
{
$system=explode(".",$name);
if (preg_match("/jpg|jpeg|JPG|JPEG/",$system[1])){$src_img=imagecreatefromjpeg($_SERVER['DOCUMENT_ROOT'] .'/kidsintranet/public_html/ideasfiles/'.$name);}
if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($_SERVER['DOCUMENT_ROOT'] .'/kidsintranet/public_html/ideasfiles/'.$name);}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$thumb_w=$new_w;
$thumb_h=$new_h;
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
Also my images input files are like so:
<input type=“file” name=“image” id=“image1”/>
<input type=“file” name=“image” id=“image2”/>
<input type=“file” name=“image” id=“image3”/>
…
…
<input type=“file” name=“image” id=“image10”/>
I get the following errors, and can’t seem work out why as it only occurs with larger images:
Warning: imagecreatefromjpeg(/home/migfreem/public_html/kidsintranet/public_html/ideasfiles/IMG_6359.JPG) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 27
Warning: imagesx(): supplied argument is not a valid Image resource in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 29
Warning: imagesy(): supplied argument is not a valid Image resource in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 30
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 51
Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 59
Warning: imagecreatefromjpeg(/home/migfreem/public_html/kidsintranet/public_html/ideasfiles/IMG_6359.JPG) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 27
Warning: imagesx(): supplied argument is not a valid Image resource in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 29
Warning: imagesy(): supplied argument is not a valid Image resource in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 30
Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 51
Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/migfreem/public_html/kidsintranet/library/Thumbnail.class.php on line 59
Can someone please assist? Any feedback would be brilliant as i am clueless as to why this is happening?
Thanks again