Jump to content

Help with images


cs1h

Recommended Posts

Hi,

 

I have a script that creates a smaller image of an original (and keeps the original as well) when it is uploaded.

 

But it can only process pictures below two mega bites, even if I increase the maxfile size in the script.

 

Does anyone know how to make it so that it can process larger images?

 

The script is,

 

<?php
if(isset($_POST['Submit']))
{
$size = 600; // the thumbnail width
$filedir = 'images/'; // the directory for the original image
$thumbdir = 'images/'; // the directory for the thumbnail image
$prefix = 'small_'; // the prefix to be added to the original name
$maxfile = '200000'; //maximum file size to upload
$mode = '0666';
$userfile_name = $_FILES['image']['name'];
$userfile_tmp = $_FILES['image']['tmp_name'];
$userfile_size = $_FILES['image']['size'];
$userfile_type = $_FILES['image']['type'];
if (isset($_FILES['image']['name']))
{
$prod_img = $filedir.$userfile_name;
$prod_img_thumb = $thumbdir.$prefix.$userfile_name;
move_uploaded_file($userfile_tmp, $prod_img);
chmod ($prod_img, octdec($mode));
$sizes = getimagesize($prod_img);
$aspect_ratio = $sizes[0]/$sizes[1];
if ($sizes[0] <= $size)
{
$new_width = $sizes[0];
$new_height = $sizes[1];
}else{
$new_width = $size;
$new_height = abs($new_width/$aspect_ratio);
}
$destimg=ImageCreateTrueColor($new_width,$new_height) or die('Problem In Creating image');
$srcimg=ImageCreateFromJPEG($prod_img) or die('Problem In opening Source Image');
ImageCopyResampled($destimg, $srcimg, 0, 0, 0, 0, $new_width, $new_height, $sizes[0], $sizes[1]) or die('Problem In resampling');
ImageJPEG($destimg,$prod_img_thumb,90) or die('Problem In saving');
imagedestroy($destimg);
}
print_r($sizes);
echo"width new: $new_width<br>height new: $new_height";
echo '
<br><a href="'.$prod_img.'">
<img src="'.$prod_img_thumb.'" width="'.$new_width.'" heigt="'.$new_height.'">
</a>';
}else{
echo '
<form method="POST" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data">
<input type="file" name="image"><p>
<input type="Submit" name="Submit" value="Submit">
</form>';
}

 

Thanks,

 

Colin

Link to comment
https://forums.phpfreaks.com/topic/85558-help-with-images/
Share on other sites

you need to change your ini file

 

; Maximum allowed size for uploaded files.

upload_max_filesize = 2M

 

 

and maybe this one

memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)

 

and maybe this

; Maximum size of POST data that PHP will accept.

post_max_size = 8M

Link to comment
https://forums.phpfreaks.com/topic/85558-help-with-images/#findComment-436750
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.