PHP - Image Upload, Fatal Error On Memory Size??
Hi
I have an upload script which uploads an image then resizes The error Code: [Select] Fatal error: Allowed memory size of 20971520 bytes exhausted (tried to allocate 7776 bytes) in Dir/UploadScript.php on line 234 The code function $strNewFileName = date("YmdHis").rand(0,5000).".".$this->strFileExt; $this->strNewFileName = $strNewFileName; $strDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir.$strNewFileName; $strTNDir = $_SERVER['DOCUMENT_ROOT'].$this->strSaveDir."tn_".$strNewFileName; move_uploaded_file($this->arrUploadFile['tmp_name'], $strDir); $image_p = imagecreatetruecolor($this->intNewWidth, $this->intNewHeight); switch($this->strFileExt){ case "jpg": $image = imagecreatefromjpeg($strDir); break; case "gif": $image = imagecreatefromgif($strDir); break; case "png": $image = imagecreatefrompng($strDir); break; } imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->intNewWidth, $this->intNewHeight, $this->intCurWidth, $this->intCurHeight); $blnSuccessUpload = false; switch($this->strFileExt){ case "jpg": if(imagejpeg($image_p, $strTNDir)){ $blnSuccessUpload = true; } break; case "gif": if(imagegif($image_p, $strTNDir)){ $blnSuccessUpload = true; } break; case "png": if(imagepng($image_p, $strTNDir)){ $blnSuccessUpload = true; } } imagedestroy($image_p); return $blnSuccessUpload; the Line causing issues (234) is Code: [Select] $image = imagecreatefromjpeg($strDir); Now that image is created but the TN is not //Edit Just a note. I have ini_set('memory_limit', 16MB); if you notice the allocated memory is less than the memory allowed. Similar TutorialsHi again, I did a simple request and i get right response from curl_exec($ch); but when i call the static method str_get_html my result is always the same. QuoteFatal error: Allowed memory size of 536870912 bytes exhausted I tried increase the memory memory_limit=2048M but the result is the same. Proof of memory limit: Memory Limit I also tried ->clear(); unset(); but doesn't work. I'm using the following library: kub-at/php-simple-html-dom-parser My code: $url = "https://www.php.net"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, []); $this->callback = HtmlDomParser::str_get_html(curl_exec($ch)); .... Any tips? I can use regular expression, but will be my last choice. Thank you! I have a wordpress site that has this error in my error logs and seems to be causing the site to load very slow: PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 64 bytes) in /home/name/public_html/wp-includes/meta.php on line 339 this is line 339: Code: [Select] $cache[$mpid][$mkey] = array(); a couple line above and below: Code: [Select] if ( !empty($meta_list) ) { foreach ( $meta_list as $metarow) { $mpid = intval($metarow[$column]); $mkey = $metarow['meta_key']; $mval = $metarow['meta_value']; // Force subkeys to be array type: if ( !isset($cache[$mpid]) || !is_array($cache[$mpid]) ) $cache[$mpid] = array(); if ( !isset($cache[$mpid][$mkey]) || !is_array($cache[$mpid][$mkey]) ) $cache[$mpid][$mkey] = array(); // Add a value to the current pid/key: $cache[$mpid][$mkey][] = $mval; } } Can some please help this is causing major issues. I'm getting a fatal memory error and have been unable to figure out what is causing it. To make it worse, the allowed memory size does not appear to be related in any way to the memory_limit value. Here's the information: Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 128 bytes) in template.php on line 164 Excerpt from template.php (line 164 is where $max is assigned): ... else if(isDateType($type) || isTimestampType($type) || isDatetimeType($type)) { $min = htmlentities($countpost['constraints'][$tablename][$fieldname]['min'], ENT_QUOTES); $max = htmlentities($countpost['constraints'][$tablename][$fieldname]['max'], ENT_QUOTES); echo "\t\tFrom: <input name=\"constraints[$tablename][$fieldname][min]\"" ." type=text value=\"$min\" onclickXSSCleaned=\"toggleCalendar(this)\" readonly>\n"; echo "\t\tTo: <input name=\"constraints[$tablename][$fieldname][max]\"" ." type=text value=\"$max\" onclickXSSCleaned=\"toggleCalendar(this)\" readonly>\n"; } ... These two lines were included at the top of the script and printed "Base Memory Usage: 473172 Memory Limit: -1": echo "Base Memory Usage: ". memory_get_usage() ."\n"; echo "Memory Limit: ". ini_get('memory_limit') ."\n"; I also get the same error in a slightly different location: Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 1 bytes) in template.php on line 153 Excerpt from template.php (line 153 is the simple variable assignment of an empty string): ... if(!isset($countpost['constraints'][$tablename][$fieldname]['value'])) $countpost['constraints'][$tablename][$fieldname]['value'] = ""; ... If I refresh the page repeatedly, the error will predictably occur at the same place. Once I change any code (even slightly), the location of the error will change to a new location, sometimes into an included file. The size of "tried to allocate X bytes" also changes. The only constant in this whole mess is the allowed memory size (which is ALWAYS 262144, no matter what the actual memory limit is). I had previously set memory_limit to -1 in the php.ini file, which seems to have no effect on the error. I am not using a .htaccess file. Changing the memory_limit doesn't change the "allowed memory size" whether it's set to 16M, 64M or whatever. I've restarted apache after each change in php.ini. I have memory_get_usage in the code several times to watch the memory. There are small changes, and a change of about 300k when I first load another file. The max gets up to 1048576 bytes (memory_get_peak_usage). 1 Mb does not seem very large to me and is much smaller than the memory_limit. Also, today I wrote a short php script to just use up memory. This was just to test php and see if my installation is messed up. It worked just fine and I got up to 128Mb used without encountering the error above. So it's something in my code. This is using php 5.3.2, apache2 2.2.14, on Ubuntu 10.04. Any insights would be greatly appreciated. Rage. The whole error message reads: Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 16 bytes) Dunno bout you but that doesn't make sense to me! Anywho I am constantly getting this error when any PHP variables are stored or anything. I'm guessing thats the case coz its saying the error is on line 6 which is: $card = rand(1,52); I tried a search on google but just got confused, is there a simple explanation why this is happening? thanks alot guys Hi. I tried to add some more if statements to check for validation and I'm now getting this error. The "on line ###" changes depending how many fields are FALSE. Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 35 bytes) in /home/content/f/u/s/fusionfashion/html/registration.php on line 133 I think it has to do with the php.ini file. So I added the memory_limit in the php.ini file. Code: [Select] register_globals = off allow_url_fopen = off expose_php = Off max_input_time = 60 variables_order = "EGPCS" extension_dir = ./ upload_tmp_dir = /tmp precision = 12 memory_limit = 128M post_max_size = 128M SMTP = relay-hosting.secureserver.net url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=,fieldset=" [Zend] zend_extension=/usr/local/zo/ZendExtensionManager.so zend_extension=/usr/local/zo/4_3/ZendOptimizer.so But I'm still getting the error. How to I check my php version and this value within a browser? <?php phpinfo() ?> Found this. Its showing 64M in LOCAL and MASTER. But I just updated the local? Hi , As you may all have experienced this problem is there way we can non-healthy exit of script ..due to memory problem........??? I got to know..we avoid this......by properly managing our php memory by unset function. remove unusable variables and objects from memory...... Is there any way we can check each time inside the script -to check memory is available or sleep for some time and check again.......to proceed without exit........ Is there a way to catch this fatal error and take necessary steps to avoid exit........ Thanks, redfort :confused: Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 4864 bytes) in /home/a5418385/public_html/scripts/status.php on line 2 What does this mean? Hello, I have no experience when dealing with large files so I am not sure what to do about this. I have attempted to read several large files using file_get_contents ; the task is to clean and munge them using preg_replace(). My code runs fine on small files ; however, the large files (40 MB) trigger an Memory exhausted error: Code: [Select] PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 41390283 bytes) I was thinking of using fread() instead but I am not sure that'll work either. Is there a workaround for this problem? Thanks for your input. Al. I'm having real difficulty with something that should simply work... I've got a script that reads files within a specific folder defined elsewhere. Then it returns the filenames (image files) to an array. Relatively simple, you'd think... Here's the process loop : Code: [Select] // Read directory for images @$dh = opendir($img_dir); while (false !== (@$filename = readdir($dh))) { if (($filename == '.') || ($filename == '..') || ($filename == 'Thumbs.db')) { } else { $files[] = $filename; } } There is a maximum of 4 images in each folder. This process will run once per page load. I have checked my php settings: memory_limit 256M post_max_size 64M upload_max_filesize 62M (just for good measure). IMHO 256m works for another site I developed which processes up to three images using imagemagick, and I've tested this with a 4mb png file too.... Yet I get this error : Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 35 bytes) in F:\html\bishopstrings\components\com_content\views\article\tmpl\default.php on line 43 This is telling me it's trying to allocate 35bytes when there is 268435456 bytes available... Yet this fails - any help Hi all I have a script that takes up to 3 images and resizes them. It works except for if you try and upload images over roughly 500kb. I then get the message: Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) Here's a snippet of the code for one image: Code: [Select] // Process image 1 : if(!empty($_FILES['image1']['name'])) { $imagelarge = $_FILES['image1']['tmp_name']; $imagelargemain = $_FILES['image1']['name']; $pathInfo = pathinfo($imagelargemain); $rand = rand(1, 100000000000000); $name = $rand . '.' . $pathInfo['extension']; $src = imagecreatefromjpeg($imagelarge); list($width,$height)=getimagesize($imagelarge); if ($width > $height) { $newwidth=600; $newheight=($height/$width)*$newwidth; } elseif ($height > $width) { $newheight=400; $newwidth=($width/$height)*$newheight; } $center_x = (600/2)-($newwidth/2); $center_y = (400/2)-($newheight/2); $tmp=imagecreatetruecolor(600,400); $white = imagecolorallocate($tmp, 255, 255, 255); imagefill($tmp, 0, 0, $white); imagecopyresampled($tmp,$src,$center_x,$center_y,0,0,$newwidth,$newheight,$width,$height); $filename = WEB_UPLOAD."images/adverts/". $name; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); $image_sql = mysql_query("UPDATE `adverts` SET image1 ='".$name."' WHERE id='".$insertid."'") or die ("Error updating database"); } Any ideas why this happens? Many thanks Pete Is there a way I can get the .jpg file in kilobytes from a remote url and check it to make sure it does not exceed 40 kilobytes before it saves the remote url into my database? Hey there so I'm using the below code to upload images/files to my server via ftp. The issue I've found is that anything bigger than 200KB either stalls out and partially uploads or doesn't upload at all. I've set my php.ini file to have upload_max_filesize = 1000M and post_max_size = 1000M. And still anything bigger than 200KB won't upload right. Any help would be appreciated. I'm using php version 5.2.14 fyi. Thanks so much. ---CODE--- <?if(!isset($_POST["submit"])){?> <!-- THE FORM ACTION IS ONTO ITSELF --> <form action="index.php" method="POST" enctype="multipart/form-data"> <input name="userfile" type="file" size="40"> <input type="submit" name="submit" value="Upload image" /> </form> <? } else { set_time_limit(30000);//i noticed that this had to be pretty big otherwise your upload was likely to stall out. $paths='/yourfilepath/yourfilepath/'; $filep=$_FILES['userfile']['tmp_name']; $ftp_server='ftp.yourdomain.com'; $ftp_user_name='your_user_name'; $ftp_user_pass='your_password'; $name=$_FILES['userfile']['name']; $conn_id = ftp_connect($ftp_server); $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); if ((!$conn_id) || (!$login_result)) { echo "FTP connection has encountered an error!"; echo "Attempted to connect to $ftp_server for user $ftp_user_name...."; exit; } else { echo ""; } $upload = ftp_put($conn_id, $paths.'/'.$name, $filep, FTP_BINARY); if (!$upload) { echo "FTP upload has encountered an error!"; } else { echo "Uploaded file with name $name Succsessfully "; } ftp_close($conn_id); } ?> Hi, I'm developing a code that uploads images. I need to verify if the image have the minimum size of 100*100 pixels before the upload. How can I do this? Best Regards, Sorry for my bad english. Hi guys, with code below i can upload pictures to database, however i need to limit the file upload. I have this code done with help of php freak forum and i am a newbie so can u help me please? thanks in advance if (isset($_POST['register']) && $_POST['register']){ //image1 $nameone=$_FILES['myfileone']['name']; if ($nameone) { $dst_filename = resize_upload_image($_FILES['myfileone'], "images/"); if ($dst_filename !== false) { extract($dst_filename); $image1 = mysql_query ("INSERT INTO img SET image='$img_filename', thumb='$thumb_filename', refimage='$reference'"); } } } ?> <form action='' method='POST' enctype='multipart/form-data'> <p>File: <input type='file' name='myfileone'> (1) What does this actually do? (compress it?) $image = imagecreatefromjpeg("image.jpg"); header('Content-Type: image/jpeg'); imagejpeg($image); By using this rather than displaying by using www.site.com/image.jpg it reduces file size of an image from 2.5mb to 0.5mb !! (2) ImageMagick can't get these results. Am I doing something wrong? If I change the pixel size of an image in ImageMagick then I can reduce its file size, but (1) above reduces file size regardless of changing pixel size. Hey My php function keeps returning an error on a valid image! I get this error: Quote could not make seekable I use this line to get the image size but i get the above error for it:$picturearray = getimagesize($Image); Url being tested : Code: [Select] http://www.fileden.com/files/2010/12/22/3043070/Sidroc.jpg The url is correct and the image does exist - does any one know what can cause this issue ? Hello guys, I'm new in php and now I'm trying to make an php installer Right now it compress php project/dump database with gzip in a file called install.php and the idea is when the user run install.php in his browser he can choose directory, overwrite existing file etc... The problem is that when I try to run install.php in firefox I get this error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 134217728 bytes) in Unknown on line 0 and when I run it with chrome I get this: <code> <?php //Compressed with Php Installer 0.5 //Directory list $directory = array(); $directory['C:\xampp\htdocs\magnatest'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/3dtags/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/__grundlayout/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/__grundlayout/bilder/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/actions/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/images/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/images/customize/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/jpgraph/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/admin/jpgraph/lang/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/attachments/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/attachments/process/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000002/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000007/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000015/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000019/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000026/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000028/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000029/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000030/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000031/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000034/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000035/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000062/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000064/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000065/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000068/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000070/'] = array( 'perms' => 16895 ); $directory['C:\xampp\htdocs\magnatest/cache/ideas/idea_0000072/'] = array( 'perms' => 16895 ); ................................................. .... ................................................. ............ ................................................. </code> Can anyone tell me what might be the problem ? Is it a memory size problem ? Hello all,
Appreciate if you folks could pls. help me understand (and more importantly resolve) this very weird error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ASC, purchase_later_flag ASC, shopper1_buy_flag AS' at line 3' in /var/www/index.php:67 Stack trace: #0 /var/www/index.php(67): PDO->query('SELECT shoplist...') #1 {main} thrown in /var/www/index.php on line 67
Everything seems to work fine when/if I use the following SQL query (which can also be seen commented out in my code towards the end of this post) :
$sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";However, the moment I change my query to the following, which essentially just includes/adds the ORDER BY clause, I receive the error quoted above: $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";In googling for this error I came across posts that suggested using "ORDER BY FIND_IN_SET()" and "ORDER BY FIELD()"...both of which I tried with no success. Here's the portion of my code which seems to have a problem, and line # 67 is the 3rd from bottom (third last) statement in the code below: <?php /* $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; */ $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY FIND_IN_SET(purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; $result = $pdo->query($sql); // foreach ($pdo->query($sql) as $row) { foreach ($result as $row) { echo '<tr>'; print '<td><span class="filler-checkbox"><input type="checkbox" name="IDnumber[]" value="' . $row["idnumber"] . '" /></span></td>';Thanks |