Hi!
Made a script for uploading and resizing images, and then making thumbnails of them.
Problem is that the script crashes with no error messages (let's say it just stops) if the image is over 1mb or so (big image in other words).
It seems like it is a memory crash, or that the scripts use too much memory (my webhotel only gives me 24mb).
What can I do about it? Is there anything in the script I can change??
Any ideas? I believe it is a memorycrash. How can I make it use less memory? Any smarter ways of doing this?PHP Code:<form action="<?php echo $_SERVER['PHP_SELF']; ?>?objectnr=<?php echo $_GET['objectnr']; ?>" method="post" enctype="multipart/form-data" id="new_image" name="new_image">
<input name="new_image1" id="new_image" size="30" type="file" class="fileUpload" />
<br />
<input name="new_image2" id="new_image" size="30" type="file" class="fileUpload" />
<br />
<input name="new_image3" id="new_image" size="30" type="file" class="fileUpload" />
<br />
<input name="new_image4" id="new_image" size="30" type="file" class="fileUpload" />
<br />
<input name="new_image5" id="new_image" size="30" type="file" class="fileUpload" />
<br />
<input name="new_image6" id="new_image" size="30" type="file" class="fileUpload" />
<br />
<input type="hidden" value="<?php echo $objectnr; ?>" name="objectnr" />
<button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
</form>
<?php
if (isset($_POST['submit'])){
echo '<br> <p>Stäng denna ruta om du är klar.</p>';
}
$max_no_img="6"; // Maximum number of images value to be set here
for($i=1; $i<=$max_no_img; $i++){
//foreach ($_FILES["new_image"]["error"] as $key => $error) {
//if ($error == UPLOAD_ERR_OK) {
$new='new_image'.$i;
if (isset ($_FILES[$new])){
//$imagename = $_FILES['new_image']['name'];
$imagename = $objectnr."-".$i;
$ext = ".jpg";
$source = $_FILES[$new]['tmp_name'];
$target = "../images/rooms/".$imagename.$ext;
if ($source!==""){
echo "<br><br>Imagename: ".$imagename.$ext;
echo "<br>Source: ".$source;
echo "<br>Target: ".$target;
}
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "../images/rooms/" . $imagepath.$ext; //This is the new file you saving
$file = "../images/rooms/" . $imagepath.$ext; //This is the original file
list($width, $height) = getimagesize($file);
if ($height>$width)
{
$modwidth = "600";
$diff = $width / $modwidth;
$modheight = $height / $diff;
}
else {
$modwidth = "800";
$diff = $width / $modwidth;
$modheight = $height / $diff;
}
//----Here is where the script stops!
$tn = imagecreatetruecolor($modwidth, $modheight);
$image = imagecreatefromjpeg($file);
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
imagejpeg($tn, $save, 100);
imagedestroy($tn);
imagedestroy($image);
//Thumbnails
$save = "../images/rooms/" . $imagepath."s".$ext; //This is the new file you saving
$file = "../images/rooms/" . $imagepath.$ext; //This is the original file
list($width, $height) = getimagesize($file);
$modwidth = "100";
$diff = $width / $modwidth;
$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight);
$image = imagecreatefromjpeg($file);
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
imagejpeg($tn, $save, 100);
imagedestroy($tn);
imagedestroy($image);
if ($source!==""){
echo "<br>Large image: ".$file;
echo "<br>Thumbnail: ".$save;
}
}
}


Reply With Quote

Bookmarks