php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2004

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 04.09.2004, 15:33  
Gast
 
Beiträge: n/a
Standard Fatal error: Allowed memory size of

Hi!
Bei diesem Script:
PHP-Code:
<script language="JavaScript" type="text/javascript">
    <!-- 
    function fenster(dateipfad, name, hoehe, breite, top, left) {
        var neu;
        neu = window.open(dateipfad, name, "width="+hoehe+",height="+breite+",top="+top+",left="+left+",scrollbars=1");
    }
    //-->
</script>
<?php
function showthumbs() {
   
$filecount 0;
   
$filecounter opendir("img/thumbnails");
   while (
$files readdir($filecounter)) {
        if (!
is_dir($files) && $files!="Thumbs.db") {
            ++
$filecount;
        }
   }
   
closedir($filecounter);
   
$direct=opendir("img/thumbnails"); 
   
$cols 4;
   
$cellpadding 5;
   
$i 0;
   if (!isset(
$_GET['gallerypage'])) { $_GET['gallerypage'] = "1"; }
   if (isset(
$_GET['gallerypage'])) { $_GET['gallerypage'] = (int)$_GET['gallerypage']; }
   if (
$_GET['lang']=="en") { 
        
$title "Gallery";
        
$site "Site";                    
   }
   if (
$_GET['lang']=="de") {
        
$title "Bilder"
        
$site "Seite";
   }
   
$width = (100*$cols)+($cellpadding*$cols*2);
   echo 
"<div align=\"center\"><h2 style=\"Border:1px #3366FF solid; color:#3366FF;width:250px;\">$title</h2></div>";
   
$ga 1;
   echo 
"
[b]<u>$site:</u> "
;
   
$filecounta $filecount;
   while (
$filecounta>20) {
        echo 
"<a href=\"index.php?lang=$_GET[lang]&link=6&gallerypage=$ga\" style=\"color: black;text-decoration:none;Border:1px #3366FF solid;Background-Color:white;display:block;float:left;width:15px;padding:2px;margin:2px;\">$ga<a>\n";
        
$filecounta-=20;
        ++
$ga;    
   }
   if (
$filecounta>0) {
        echo 
"<a href=\"index.php?lang=$_GET[lang]&link=6&gallerypage=$ga\" style=\"color: black;text-decoration:none;Border:1px #3366FF solid;Background-Color:white;display:block;float:left;width:15px;padding:2px;margin:2px;\">$ga<a>\n";   
   }
   echo 
"[/b]


"
;
   echo 
"<table align=\"center\"><tr>";
   while (
$file readdir ($direct)) { 
    if (!
is_dir($file) && $file!="Thumbs.db") {
            
$oberlimit $_GET[gallerypage]*20;
            
$unterlimit $oberlimit-20;
            if (
$i<$oberlimit && $i>=$unterlimit) {
            
$filesize filesize("img/thumbnails/".$file);
            
$filesize round($filesize/10240);
            
$file ereg_replace("( )""%20"$file);
            
$d = ($i/$cols);
            if (
gettype($d)=="integer") {
                echo 
"</tr>";
                echo 
"<tr cellpadding=\"$cellpadding px\">";
                echo 
"<td style=\"padding:3px;Border:1px #3366FF solid;Background-Color:#C2C2C2;text-align:center;color:maroon\">";
                echo 
"<a href=\"javascript:fenster('viewgallery.php?file=$file&id=$i&lang=$_GET[lang]','Exmouth 2004','655px','800px','100px','100px')\" class=\"d\">";
                echo 
"<img src=\"img/thumbnails/$file\" border=0>";
                echo 
"</a>
[b]Size:[/b] $filesize KB</td>\n"
;  
            }
            else {
                echo 
"<td style=\"padding:3px;Border:1px #3366FF solid;Background-Color:#C2C2C2;text-align:center;color:maroon\">";
                echo 
"<a href=\"javascript:fenster('viewgallery.php?file=$file&id=$i&lang=$_GET[lang]','Exmouth 2004','655px','800px','100px','100px')\" class=\"d\">";
                echo 
"<img src=\"img/thumbnails/$file\" border=0 alt=$filesize>";
                echo 
"</a>
[b]Size:[/b] $filesize KB</td>\n"
;              
            }
           }
     ++
$i;
     }
   }
   
closedir($direct); 
   echo 
"</table>";
   
$g 1;
   echo 
"
[b]<u>Seite:</u> "
;
   while (
$filecount>20) {
        echo 
"<a href=\"index.php?lang=$_GET[lang]&link=6&gallerypage=$g\" style=\"color: black;text-decoration:none;Border:1px #3366FF solid;Background-Color:white;display:block;float:left;width:15px;padding:2px;margin:2px;\">$g<a>\n";
        
$filecount-=20;
        ++
$g;    
   }
   if (
$filecount>0) {
        echo 
"<a href=\"index.php?lang=$_GET[lang]&link=6&gallerypage=$g\" style=\"color: black;text-decoration:none;Border:1px #3366FF solid;Background-Color:white;display:block;float:left;width:15px;padding:2px;margin:2px;\">$g<a>\n";   
   }
   echo 
"[/b]
"
;
}

 function 
make_thumbs() {
   
$verz=opendir ("img/original/"); 
   while (
$fileb readdir ($verz)) { 
                       if (!
is_dir($fileb) && $fileb!="Thumbs.db") { 
                           
$groesse "100";
                           
$img_src "img/original/".$fileb;
                           
$img_height "100";
                           
$img_width "100";
                           
$im imagecreatefromjpeg($img_src);
                           list(
$src_width$src_height) = getimagesize($img_src);
                           if(
$src_width >= $src_height) {
                             
$new_image_width $img_width;
                             
$new_image_height $src_height $img_width $src_width;
                           }
                           if(
$src_width $src_height) {
                             
$new_image_height $img_width;
                             
$new_image_width $src_width $img_height $src_height;
                           }
                           
$new_image imagecreatetruecolor($new_image_width$new_image_height);
                           
imagecopyresampled($new_image$im0000$new_image_width,$new_image_height$src_width$src_height);
                           
imagejpeg($new_image"img/thumbnails/".$fileb90);
                       } 
                   }
                   
closedir($verz);

 }
 
 function 
make_big() {
   
$verz=opendir ("img/original"); 
   while (
$fileb readdir ($verz)) { 
                       if (!
is_dir($fileb) && $fileb!="Thumbs.db") { 
                           
$groesse "100";
                           
$img_src "img/original/".$fileb;
                           
$img_height "480";
                           
$img_width "640";
                           
$im imagecreatefromjpeg($img_src);
                           list(
$src_width$src_height) = getimagesize($img_src);
                           if(
$src_width >= $src_height) {
                             
$new_image_width $img_width;
                             
$new_image_height $src_height $img_width $src_width;
                           }
                           if(
$src_width $src_height) {
                             
$new_image_height $img_width;
                             
$new_image_width $src_width $img_height $src_height;
                           }
                           
$new_image imagecreatetruecolor($new_image_width$new_image_height);
                           
imagecopyresampled($new_image$im0000$new_image_width,$new_image_height$src_width$src_height);
                           
imagejpeg($new_image"img/big/".$fileb90);
                       } 
                   }
                   
closedir($verz);

 }

function 
pruefung() {
    
$digi opendir("img/original");
    
$doriginal 0;
    while (
$filedi readdir($digi)) {
        if (!
is_dir($filedi) && $filedi!="Thumbs.db") {
            ++
$doriginal;
        }
    }
    
closedir($digi);
    
    
$diga opendir("img/thumbnails");
    
$dthumbs 0;
    while (
$filedg readdir($diga)) {
        if (!
is_dir($filedg) && $filedg!="Thumbs.db") {
            ++
$dthumbs;
        }
    }
    
closedir($diga);
    
    
$digb opendir("img/big");
    
$dbig 0;
    while (
$filedbig readdir($digb)) {
        if (!
is_dir($filedbig) && $filedbig!="Thumbs.db") {
            ++
$dbig;
        }
    }
    
closedir($digb);
    
    if (
$doriginal==$dthumbs and $dbig==$dthumbs) {
        
showthumbs();
    }
    if ((
$doriginal!=$dthumbs) or ($dbig!=$dthumbs) or ($doriginal!=$dbig)) {
        echo 
"Original: $doriginal
Thumbs: $dthumbs
big: $dbig"
;
        
make_thumbs();
        
make_big();
        
showthumbs();
    }
}
 
pruefung();

 
?>
 </body>
</html>
tritt bei meinem gemieteten Webspace dieser Fehler auf (daheim auf meinem Webserver funktioniert das Script ohne jegliche Fehlermeldung):

Fatal error: Allowed memory size of 16777216 bytes exhausted at (null):0 (tried to allocate 8192 bytes) in /home/htdocs/web79/html/exmouth2004/gallery.php on line 98

Liegt das am Server oder am Script???
thx
marce23
 
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 04.09.2004, 16:26  
Gast
 
Beiträge: n/a
Standard

hab jetzt herausgefunden, dass das mit dem memory_limit eintrag in der php.ini zusammenhängt, aber auf die hab ich bei meinem Webspace anbieter keinen Zugriff. Was soll ich jetzt machen?
 
Alt 04.09.2004, 17:09  
Waq
Erfahrener Benutzer
 
Registriert seit: 15.08.2004
Beiträge: 2.473
Waq
Standard

Ich würde mal ein paar imagedestroy()s sinnvoll verteilen, so dass Du allen Speicher, den Du durch Bilder reservierst, auch wieder freigiebst, wennn du ihn nicht mehr brauchst.
http://de3.php.net/imagedestroy
__________________
mod = master of disaster
Waq ist offline  
Alt 04.09.2004, 17:14  
Gast
 
Beiträge: n/a
Standard

das hab ich jetzt auch gemacht:

PHP-Code:
...
function 
make_thumbs() {
   
$verz=opendir ("img/original/"); 
   while (
$fileb readdir ($verz)) { 
                       if (!
is_dir($fileb) && $fileb!="Thumbs.db") { 
                           
$groesse "100";
                           
$img_src "img/original/".$fileb;
                           
$img_height "100";
                           
$img_width "100";
                           
$im imagecreatefromjpeg($img_src);
                           list(
$src_width$src_height) = getimagesize($img_src);
                           if(
$src_width >= $src_height) {
                             
$new_image_width $img_width;
                             
$new_image_height $src_height $img_width $src_width;
                           }
                           if(
$src_width $src_height) {
                             
$new_image_height $img_width;
                             
$new_image_width $src_width $img_height $src_height;
                           }
                           
$new_image imagecreatetruecolor($new_image_width$new_image_height);
                           
imagecopyresampled($new_image$im0000$new_image_width,$new_image_height$src_width$src_height);
                           
imagejpeg($new_image"img/thumbnails/".$fileb90);
                           
imagedestroy($new_image);
imagedestroy($img_src);
                       } 
                   }
                   
closedir($verz);

 }
 
 function 
make_big() {
   
$verz=opendir ("img/original"); 
   while (
$fileb readdir ($verz)) { 
                       if (!
is_dir($fileb) && $fileb!="Thumbs.db") { 
                           
$groesse "100";
                           
$img_src "img/original/".$fileb;
                           
$img_height "480";
                           
$img_width "640";
                           
$im imagecreatefromjpeg($img_src);
                           list(
$src_width$src_height) = getimagesize($img_src);
                           if(
$src_width >= $src_height) {
                             
$new_image_width $img_width;
                             
$new_image_height $src_height $img_width $src_width;
                           }
                           if(
$src_width $src_height) {
                             
$new_image_height $img_width;
                             
$new_image_width $src_width $img_height $src_height;
                           }
                           
$new_image imagecreatetruecolor($new_image_width$new_image_height);
                           
imagecopyresampled($new_image$im0000$new_image_width,$new_image_height$src_width$src_height);
                           
imagejpeg($new_image"img/big/".$fileb90);
                                   
imagedestroy($new_image);
imagedestroy($img_src);
                       } 
                   }
                   
closedir($verz);
... 
Es funktioniert aber immer noch nicht!!!
 
Alt 04.09.2004, 17:50  
Waq
Erfahrener Benutzer
 
Registriert seit: 15.08.2004
Beiträge: 2.473
Waq
Standard

Dann würde ich mal
http://de3.php.net/memory_get_usage
nehmen und mich ans debuggen machen, um rauszufinden, wo denn der Speicher verbraten wird.
__________________
mod = master of disaster
Waq ist offline  
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
[PHP] preg_replace Fatal Error I-Spy PHP Tipps 2006 7 04.06.2006 20:53
Memory exhausted PHP Tipps 2005-2 2 29.08.2005 19:47
[Erledigt] Fatal error: Allowed memory size... PHP Tipps 2005-2 5 07.07.2005 13:01
Allowed Memory Size exhausted bicpi PHP-Fortgeschrittene 16 20.04.2005 00:28
different size in shared object, consider re-linking!? Heart Datenbanken 1 09.03.2005 15:42
Fatal error: Allowed memory size of 8192 bytes exhausted at PHP Tipps 2005 11 06.03.2005 19:26
Fatal error: Call to undefined function: imagecreatefromjpeg DannyD PHP-Fortgeschrittene 10 05.12.2004 21:59
[Erledigt] imagecreatetruecolor memory size PHP-Fortgeschrittene 2 10.09.2004 17:52
[Erledigt] Memory Problem mit gd PHP-Fortgeschrittene 1 25.06.2004 18:45

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
allowed memory size of bytes exhausted n, php opendir allowed memory, php readdir fatal error: allowed memory size, allowed memory size is_dir, $new_image_width = round(($img_height / $src_height) * $src_width);

Alle Zeitangaben in WEZ +2. Es ist jetzt 02:48 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.