473,735 Members | 6,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fatal error: Alowed memory size of 8388608 bytes exhausted ....

1 New Member
I am kinda new to php, but i do know what i am doing kinda, but i came across this error when i am trying to upload a file to my website.

Expand|Select|Wrap|Line Numbers
  1. Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 3714000 bytes) in /opt/lampp/htdocs/tutorials/php-mysql-tutorial/admin/image-gallery/library/functions.php on line 104
Platform:
Ubuntu 8.04 LST (where i make my programs, and test them before i upload them), Using XAMPP for Linux 1.6.7, Apache
Server:
Fedora release 7 (Moonshine)
2.6.9-023stab044.4-smp #1 SMP Thu May 24 17:20:37 MSD 2007 i686 i686 i386 GNU/Linux


Source of
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. /*    
  4.     Details for:    'functions.php'
  5.         Auther:        Franocis Venter
  6.         Domain:        main.theshadowgfx.com
  7.         Copyright:     (c) 2008 The ShadowGFX            
  8.     End Details
  9.  
  10.  
  11.     Upload an image and create the thumbnail. The thumbnail is stored 
  12.  
  13.     under the thumbnail sub-directory of $uploadDir.
  14.  
  15.  
  16.  
  17.     Return the uploaded image name and the thumbnail also.
  18.  
  19. */
  20.  
  21. function uploadImage($inputName, $uploadDir)
  22.  
  23. {
  24.  
  25.     $image     = $_FILES[$inputName];
  26.  
  27.     $imagePath = '';
  28.  
  29.     $thumbnailPath = '';
  30.  
  31.  
  32.  
  33.     // if a file is given
  34.  
  35.     if (trim($image['tmp_name']) != '') {
  36.  
  37.         $ext = substr(strrchr($image['name'], "."), 1); 
  38.  
  39.  
  40.  
  41.         // generate a random new file name to avoid name conflict
  42.  
  43.         // then save the image under the new file name
  44.  
  45.         $imagePath = md5(rand() * time()) . ".$ext";
  46.  
  47.         $result    = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);
  48.  
  49.  
  50.  
  51.         if ($result) {
  52.  
  53.             // create thumbnail
  54.  
  55.             $thumbnailPath =  md5(rand() * time()) . ".$ext";
  56.  
  57.             $result = createThumbnail($uploadDir . $imagePath, $uploadDir . 'thumbnail/' . $thumbnailPath, THUMBNAIL_WIDTH);
  58.  
  59.  
  60.  
  61.             // create thumbnail failed, delete the image
  62.  
  63.             if (!$result) {
  64.  
  65.                 unlink($uploadDir . $imagePath);
  66.  
  67.                 $imagePath = $thumbnailPath = '';
  68.  
  69.             } else {
  70.  
  71.                 $thumbnailPath = $result;
  72.  
  73.             }    
  74.  
  75.         } else {
  76.  
  77.             // the image cannot be uploaded
  78.  
  79.             $imagePath = $thumbnailPath = '';
  80.  
  81.         }
  82.  
  83.  
  84.  
  85.     }
  86.  
  87.  
  88.  
  89.  
  90.  
  91.     return array('image' => $imagePath, 'thumbnail' => $thumbnailPath);
  92.  
  93. }
  94.  
  95.  
  96.  
  97. /*
  98.  
  99.     Create a thumbnail of $srcFile and save it to $destFile.
  100.  
  101.     The thumbnail will be $width pixels.
  102.  
  103. */
  104.  
  105. function createThumbnail($srcFile, $destFile, $width, $quality = 75)
  106.  
  107. {
  108.  
  109.     $thumbnail = '';
  110.  
  111.  
  112.  
  113.     if (file_exists($srcFile)  && isset($destFile))
  114.  
  115.     {
  116.  
  117.         $size        = getimagesize($srcFile);
  118.  
  119.         $w           = number_format($width, 0, ',', '');
  120.  
  121.         $h           = number_format(($size[1] / $size[0]) * $width, 0, ',', '');
  122.  
  123.  
  124.  
  125.         $thumbnail =  copyImage($srcFile, $destFile, $w, $h, $quality);
  126.  
  127.     }
  128.  
  129.  
  130.  
  131.     // return the thumbnail file name on sucess or blank on fail
  132.  
  133.     return basename($thumbnail);
  134.  
  135. }
  136.  
  137.  
  138.  
  139. /*
  140.  
  141.     Copy an image to a destination file. The destination
  142.  
  143.     image size will be $w X $h pixels
  144.  
  145. */
  146.  
  147. function copyImage($srcFile, $destFile, $w, $h, $quality = 75)
  148.  
  149. {
  150.  
  151.     $tmpSrc     = pathinfo(strtolower($srcFile));
  152.  
  153.     $tmpDest    = pathinfo(strtolower($destFile));
  154.  
  155.     $size       = getimagesize($srcFile);
  156.  
  157.  
  158.  
  159.     if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
  160.  
  161.     {
  162.  
  163.        $destFile  = substr_replace($destFile, 'jpg', -3);
  164.  
  165.        $dest      = imagecreatetruecolor($w, $h);
  166.  
  167.        //imageantialias($dest, TRUE);
  168.  
  169.     } elseif ($tmpDest['extension'] == "png") {
  170.  
  171.        $dest = imagecreatetruecolor($w, $h);
  172.  
  173.        //imageantialias($dest, TRUE);
  174.  
  175.     } else {
  176.  
  177.       return false;
  178.  
  179.     }
  180.  
  181.  
  182.  
  183.     switch($size[2])
  184.  
  185.     {
  186.  
  187.        case 1:       //GIF
  188.  
  189.            $src = imagecreatefromgif($srcFile);
  190.  
  191.            break;
  192.  
  193.        case 2:       //JPEG
  194.  
  195.            $src = imagecreatefromjpeg($srcFile);
  196.  
  197.            break;
  198.  
  199.        case 3:       //PNG
  200.  
  201.            $src = imagecreatefrompng($srcFile);
  202.  
  203.            break;
  204.  
  205.        default:
  206.  
  207.            return false;
  208.  
  209.            break;
  210.  
  211.     }
  212.  
  213.  
  214.  
  215.     imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
  216.  
  217.  
  218.  
  219.     switch($size[2])
  220.  
  221.     {
  222.  
  223.        case 1:
  224.  
  225.        case 2:
  226.  
  227.            imagejpeg($dest,$destFile, $quality);
  228.  
  229.            break;
  230.  
  231.        case 3:
  232.  
  233.            imagepng($dest,$destFile);
  234.  
  235.     }
  236.  
  237.     return $destFile;
  238.  
  239.  
  240.  
  241. }
  242.  
  243.  
  244.  
  245. /*
  246.  
  247.     Check if the user is logged in or not
  248.  
  249. */
  250.  
  251. function checkLogin()
  252.  
  253. {
  254.  
  255.     if (!isset($_SESSION['isLogin']) || $_SESSION['isLogin'] == false) {
  256.  
  257.         header('Location: login.php');
  258.  
  259.         exit;
  260.  
  261.     }
  262.  
  263. }
  264.  
  265.  
  266.  
  267. /*
  268.  
  269.     Create the link for moving from one page to another
  270.  
  271. */
  272.  
  273. function getPagingLink($totalResults, $pageNumber, $itemPerPage = 10, $strGet = '')
  274.  
  275. {
  276.  
  277.     $pagingLink    = '';
  278.  
  279.     $totalPages    = ceil($totalResults / $itemPerPage);
  280.  
  281.  
  282.  
  283.     // how many link pages to show
  284.  
  285.     $numLinks      = 10;
  286.  
  287.  
  288.  
  289.     // create the paging links only if we have more than one page of results
  290.  
  291.     if ($totalPages > 1) {
  292.  
  293.         $self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;
  294.  
  295.  
  296.  
  297.         // print 'previous' link only if we're not
  298.  
  299.         // on page one
  300.  
  301.         if ($pageNumber > 1) {
  302.  
  303.             $page = $pageNumber - 1;
  304.  
  305.             if ($page > 1) {
  306.  
  307.                 $prev = " <a href=\"$self?pageNum=$page&$strGet\">[Prev]</a> ";
  308.  
  309.             } else {
  310.  
  311.                 $prev = " <a href=\"$self?$strGet\">[Prev]</a> ";
  312.  
  313.             }    
  314.  
  315.  
  316.  
  317.             $first = " <a href=\"$self?$strGet\">[First]</a> ";
  318.  
  319.         } else {
  320.  
  321.             $prev  = ''; // we're on page one, don't show 'previous' link
  322.  
  323.             $first = ''; // nor 'first page' link
  324.  
  325.         }
  326.  
  327.  
  328.  
  329.         // print 'next' link only if we're not
  330.  
  331.         // on the last page
  332.  
  333.         if ($pageNumber < $totalPages) {
  334.  
  335.             $page = $pageNumber + 1;
  336.  
  337.             $next = " <a href=\"$self?pageNum=$page&$strGet\">[Next]</a> ";
  338.  
  339.             $last = " <a href=\"$self?pageNum=$totalPages&$strGet\">[Last]</a> ";
  340.  
  341.         } else {
  342.  
  343.             $next = ''; // we're on the last page, don't show 'next' link
  344.  
  345.             $last = ''; // nor 'last page' link
  346.  
  347.         }
  348.  
  349.  
  350.  
  351.         $start = $pageNumber - ($pageNumber % $numLinks) + 1;
  352.  
  353.         $end   = $start + $numLinks - 1;        
  354.  
  355.  
  356.  
  357.         $end   = min($totalPages, $end);
  358.  
  359.  
  360.  
  361.         $pagingLink = array();
  362.  
  363.         for($page = $start; $page <= $end; $page++)    {
  364.  
  365.             if ($page == $pageNumber) {
  366.  
  367.                 $pagingLink[] = " $page ";   // no need to create a link to current page
  368.  
  369.             } else {
  370.  
  371.                 if ($page == 1) {
  372.  
  373.                     $pagingLink[] = " <a href=\"$self?$strGet\">$page</a> ";
  374.  
  375.                 } else {    
  376.  
  377.                     $pagingLink[] = " <a href=\"$self?pageNum=$page&$strGet\">$page</a> ";
  378.  
  379.                 }    
  380.  
  381.             }
  382.  
  383.  
  384.  
  385.         }
  386.  
  387.  
  388.  
  389.         $pagingLink = implode(' | ', $pagingLink);
  390.  
  391.  
  392.  
  393.         // return the page navigation link
  394.  
  395.         $pagingLink = $first . $prev . $pagingLink . $next . $last;
  396.  
  397.     }
  398.  
  399.  
  400.  
  401.     return $pagingLink;
  402.  
  403. }
  404.  
  405.  
  406.  
  407. /*
  408.  
  409.     Display the breadcrumb navigation on top of the gallery page
  410.  
  411. */
  412.  
  413. function showBreadcrumb()
  414.  
  415. {
  416.  
  417.     if (isset($_GET['album'])) { 
  418.  
  419.         $album = $_GET['album'];
  420.  
  421.         $sql  = "SELECT al_name
  422.  
  423.                  FROM tbl_album
  424.  
  425.                  WHERE al_id = $album";
  426.  
  427.  
  428.  
  429.         $result = mysql_query($sql) or die('Error, get album name failed. ' . mysql_error());
  430.  
  431.         $row = mysql_fetch_assoc($result);
  432.  
  433.         echo ' &gt; <a href="index.php?page=list-image&album=' . $album . '">' . $row['al_name'] . '</a>';
  434.  
  435.  
  436.  
  437.         if (isset($_GET['image'])) {
  438.  
  439.             $image = $_GET['image'];
  440.  
  441.             $sql  = "SELECT im_title
  442.  
  443.                      FROM tbl_image
  444.  
  445.                      WHERE im_id = $image";
  446.  
  447.  
  448.  
  449.             $result = mysql_query($sql) or die('Error, get image name failed. ' . mysql_error());
  450.  
  451.             $row = mysql_fetch_assoc($result);
  452.  
  453.  
  454.  
  455.             echo ' &gt; <a href="index.php?page=image-detail&album=' . $album . '&image=' . $image . '">' . $row['im_title'] . '</a>';
  456.  
  457.         }
  458.  
  459.     }
  460.  
  461. }
  462.  
  463.  
  464.  
  465. ?>
  466.  
Jul 27 '08 #1
1 2933
hsriat
1,654 Recognized Expert Top Contributor
I didn't check your code, but there's a problem inside one of your for loop or while loop. To find out which loop is giving this error, check the line no. 104 (whichever is pointed out by error message)
Jul 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4689
by: Phil Powell | last post by:
Actually the client is saying it sometimes happens and sometimes doesn't happen, and when they refresh their screen it clears itself (I assume the memory clears). Here is line 1135: $result = mysql_query($this->query, $this->dbcnx) or die(@include("$DOCUMENT_ROOT${devpath}errors/query_error.php")); It is found here in this class method:
3
3560
by: Bob Bedford | last post by:
I'm trying to save an XML file sent to me in ZIP format. Here is the code: if($XMLFile=fopen($XMLPath.strtoupper(substr($file,0,strlen($file)-4)).".XML",'w')) if(fwrite($XMLFile,zip_entry_read($zip_entry,zip_entry_filesize($zip_entry)))){ here is the error: Allowed memory size of 8388608 bytes exhausted (....) The problem occurs on the "fwrite" function.
2
4856
by: Gonzalo | last post by:
Just upgraded php (5.0.3) - compiled from source. I'm trying to upgrade & install some Pear packages but get the following error: $ pear upgrade pear downloading PEAR-1.3.5.tgz ... Starting to download PEAR-1.3.5.tgz (108,423 bytes) ..........................done: 108,423 bytes PHP Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
5
7803
by: tdavidge | last post by:
I've just noticed the following errors in my db2diag.log file: 2003-07-18-01.29.18.203000-240 E3301H585 LEVEL: Severe (OS) PID : 1532 TID : 2944 PROC : db2syscs.exe INSTANCE: DB2 NODE : 000 DB : DBNAME APPHDL : 0-958 APPID: *LOCAL.DB2.030718052918 FUNCTION: DB2 UDB, oper system services, getPrivateChunksFromOs, probe:100 CALLED : OS, -, VirtualAlloc OSERR ...
0
2297
by: prabhjeet | last post by:
I have DB2 v9 trial version installed on Windows 2003 Server with 1GB RAM. I am able to connect remotely through an ODBC data source to the database, but when I try to connect to that data source using my application, I get the following error in db2diag.log: 2007-02-20-10.41.37.812000+330 E1562H677 LEVEL: Warning (OS) PID : 3720 TID : 2000 PROC : db2syscs.exe INSTANCE: DB2 NODE : 000 DB : TEST APPHDL : 0-63 APPID:...
1
2977
by: Kimmo Laine | last post by:
Hi! We've encountered a strange problem concerning memory usage. In the previous install the maximum memory amount per page was limited to 8 MB and it was never reached. Now, after upgrading both hardware and software, running the same scripts that used to be fine with 8 MB hit the roof all the time. The maximum memory allocation was set to 128 MB and still PHP encounters fatal errors with allowed memory size exhausted. Pardon my french,...
3
3016
by: spereira | last post by:
I am running XAMPP for Mac OS X 0.6.1 ! And since it did not have PDF libarires I downloaded ezpdf from the url:http://sourceforge.net/project/showfiles.php?group_id=45168&package_id=37830&release_id=147645 unzipped into a folder pdf_test And tried to run from the local http://localhost/pdf_test/readme.php gets the error Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 76912 bytes) in...
1
1773
by: santrooper | last post by:
Hello all, I am trying to unpack big wav file (more than 10 mb), because i want to generate Visualization of an wav file, for smaller files (less than 2 mb) it works fine, but for bigger files it gives Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 35 bytes) in /var/www/phptest/mp3processor/thescript.php on line 64 I am pesting the code below PLEASE HELP ==================== <? class wavVisualization{...
0
8962
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8785
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9463
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4822
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3273
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.