473,508 Members | 2,255 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 2908
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
4671
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 =...
3
3550
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'))...
2
4844
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...
5
7775
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 :...
0
2274
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...
1
2953
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...
3
3006
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...
1
1763
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...
0
7229
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,...
0
7129
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...
0
7333
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,...
0
7398
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...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5057
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...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1566
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 ...
0
428
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...

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.