Jump to content

uploading images


Woodburn2006

Recommended Posts

i am creating a script to upload images to the server. the script works fine with smaller images but when i try to upload a large sized image it does not work.

 

function createthumb($name,$filename,$new_w,$new_h)
{
	$system=explode('.',$name); // split filename either side of the '.'
	if (preg_match('/jpg|jpeg/',$system[1])){ // if extension is jpg or jpeg
		$src_img=imagecreatefromjpeg($name); // create a copy of the image in jpg
	}
	if (preg_match('/png/',$system[1])){ // if extension is png
		$src_img=imagecreatefrompng($name); // create a copy of the image in png
	}
	$old_x=imageSX($src_img); // gets width of original image
	$old_y=imageSY($src_img); // gets height of original image
	if ($old_x > $old_y) { // if img is wider than high
		$thumb_w=$new_w; // sets width variable of new img
		$thumb_h=$old_y*($new_h/$old_x); // sets height variable by doing: height = original width * (100 / original height)
	}
	if ($old_x < $old_y) { // other way around from setting wider than high
		$thumb_w=$old_x*($new_w/$old_y);
		$thumb_h=$new_h;
	}
	if ($old_x == $old_y) { // if img is square sets variabls straight forwardly
		$thumb_w=$new_w;
		$thumb_h=$new_h;
	}
	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // creates image
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // copies into new image
	if (preg_match("/png/",$system[1])) // if old file extension is png
	{
		imagepng($dst_img,$filename); // extension of new image is png
	} else {
		imagejpeg($dst_img,$filename); // else extension of new image is jpeg or jpg
	}
	imagedestroy($dst_img); //destroys variable
	imagedestroy($src_img); 
}

 

any ideas why this may be happening.

 

to see the results got to http://www.ontherocks.me.uk/cp

user: lee

pass: ontherocks

Link to comment
https://forums.phpfreaks.com/topic/153766-uploading-images/
Share on other sites

my max upload is 12mb so that isnt a problem, would it be the max_execution_time as that is set to 30 seconds?

 

if so how would i change it go last longer or even infinately?

 

I usually only call this at run-time which would be done by putting this at the top of the script file

<?php
set_time_limit(0);
?>

Link to comment
https://forums.phpfreaks.com/topic/153766-uploading-images/#findComment-810020
Share on other sites

You are either getting an upload error due to the size or a memory error due to the resizing. Find out if it is a memory problem by adding the following two lines immediately after your first opening <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
https://forums.phpfreaks.com/topic/153766-uploading-images/#findComment-810064
Share on other sites

i have this code at the beginning of the script:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);
set_time_limit(0);

 

and these are the errors i get

 

Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit in safe mode in /customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/cp/images/add.php on line 5

Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 15552 bytes) in /customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/cp/functions.php on line 19

 

looking like a combination. anything i can do about this?

Link to comment
https://forums.phpfreaks.com/topic/153766-uploading-images/#findComment-810204
Share on other sites

now i ge tthis:

 

Fatal error: Allowed memory size of 25165824 bytes exhausted (tried to allocate 15552 bytes) in /customers/ontherocks.me.uk/ontherocks.me.uk/httpd.www/cp/functions.php on line 19

 

starting to get a bit irritating now. no matter what memory limit im entering it comes up with the same error msg and same bytes

Link to comment
https://forums.phpfreaks.com/topic/153766-uploading-images/#findComment-811003
Share on other sites

20M is only 20971520 bytes, so had that worked it would have reduced the amount of memory.

 

Assuming you put that ini_set() statement in your code before the point that the code needed more memory, your host has disabled your ability to change the memory_limit. The safe_mode does not state it prevents you from changing this, but that might just be a documentation error.

 

You need to ask your host if or how you can change the memory_limit.

Link to comment
https://forums.phpfreaks.com/topic/153766-uploading-images/#findComment-811046
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.