Jump to content

Recommended Posts

I host a webpage that has a few pics from some events that we are a part of.  I am lazy and dont want to write a new webpage for each event nor convert the files to view and create thumbnails for them all.  So I upload a bunch of full sized pictures to the server, about 2816x2112 no more then 5MBs and no less then 1.5MBs in size.  Then I have it read them all into an array and have it create 2 new files one 800x600 to view and another 125x125 for thumbnails.  My script works super, however it wont do more then 25 pics at a time. 

 

If I want more then 25, I have to manually do it in the script myself by adding the name of the file instead of automating it.

 

I believe this is a memory issue, but I could be wrong.  I am not that familiar with php.ini, and would imagine that there is a variable I need to change to allow more pics to be stored in the array.  Does anyone know what the variable name I need to change is and what value I should try?

 

 

Link to comment
https://forums.phpfreaks.com/topic/67113-max-array-size/
Share on other sites

You can't store an image itself in an array, your pobably just storing a string which points to the file path of the image. We need to see some code. As far as I know there is no limit to the size or dimensions of an array in php, well, not until you run out of ram. even if there was, 25 certainly would not be it.

Link to comment
https://forums.phpfreaks.com/topic/67113-max-array-size/#findComment-336693
Share on other sites

Here is my code.  Your point is well taken, I guess I have no idea why it will only do 25.  Help me please! 

 

<?php 
// Generates thumbnails of given dir from previous form


// Functions ----------------------------------------------------------------------------------->
function ditchtn($arr,$thumbname){  // Filter out thumbnails
foreach ($arr as $item)	{
	if (!preg_match("/^".$thumbname."/",$item)){$tmparr[]=$item;}}
return $tmparr;
}

/*
variables:
$name		Original filename
$filename	Filename of the resized image
$new_w		width of resized image
$new_h		height of resized image
*/	
function createthumb($name,$filename,$new_w,$new_h,$x)
{
$system=explode(".",$name);  // Seperate each name and store into $system
echo "<font color=\"#CCCCCC\" size=\"3\">$x. Name: $name</font><br><br>";
if(eregi("jpg",$name)){$src_img=imagecreatefromjpeg($name);} // If jpg create jpg image
if(eregi("png",$name)){$src_img=imagecreatefrompng($name);}  // If png create png image

$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y) {
	$thumb_w=$new_w;
	$thumb_h=$old_y*($new_h/$old_x);}
if ($old_x < $old_y) {
	$thumb_w=$old_x*($new_w/$old_y);
	$thumb_h=$new_h;}
if ($old_x == $old_y) {
	$thumb_w=$new_w;
	$thumb_h=$new_h;}

$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
if (preg_match("/png/",$system[1]))	{
	imagepng($dst_img,$filename); } 
else{imagejpeg($dst_img,$filename); }

imagedestroy($dst_img); 
imagedestroy($src_img); 
}

/*
        Function directory($directory,$filters)
        reads the content of $directory, takes the files that apply to $filter 
	and returns an array of the filenames.
        You can specify which files to read, for example
        $files = directory(".","jpg,gif");
                gets all jpg and gif files in this directory.
        $files = directory(".","all");
                gets all files.
*/
function directory($dir,$filters)
{
$handle=opendir($dir);
$files=array();
if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
if ($filters != "all"){
	$filters=explode(",",$filters);
	while (($file = readdir($handle))!==false){
		for ($f=0;$f<sizeof($filters);$f++):
			$system=explode(".",$file);
			if ($system[1] == $filters[$f]){$files[] = $file;}
		endfor;	}}
closedir($handle);
return $files;
}
// Begin Page ----------------------------------------------------------------------------------->
?>

 

<?php
  // Creating thumbnails and displaying status
    $picdir='Students/Pics/'.$HTTP_GET_VARS['event']."/";      
    $thumbdir=$picdir;            
    $pics=directory($picdir,"jpg,JPG,JPEG,jpeg,png,PNG");
    $pics=ditchtn($pics,"tn_");
    $pics=ditchtn($pics,"rs_");
    $x=0;

    if ($pics[0]!=""){
      foreach ($pics as $p)	{
        $x++;
        createthumb($picdir.$p,$thumbdir."tn_".$p,125,125,$x);
        createthumb($picdir.$p,$thumbdir."rs_".$p,800,800,$x);}}
php?>

Link to comment
https://forums.phpfreaks.com/topic/67113-max-array-size/#findComment-336729
Share on other sites

Your ability to receive a good response to your question is directly proportional to the quality  of information you provide.

 

however it wont do more then 25 pics at a time.

 

What does that mean? Do you get an error, a blank page, or what? Is it EXACTLY 25 images where it breaks? Does 24 images work every time?

 

Without more information my "guess" would be a timeout issue. Those are very big images and the time to resize them might take more time than allowed for your server settings (maxexecutionttime I believe). That setting can be changes in the php.ini file.

 

However, since you are manually uploading these images you could save yourself a lot of grief by just resizing them to 800x600 and then letting the PHP create the thumbs. MS has a freeware app as part of it's power tools called imageresizer. You can right-click on a group of images and resize them all at once. Then it would also take you a lot less time to upload the files.

Link to comment
https://forums.phpfreaks.com/topic/67113-max-array-size/#findComment-338825
Share on other sites

Thankyou for your reply.  I want the full image up there for downloading by others, so resizing them ahead of time isnt much of a solution.  Yes the files are big, yes it takes a while, and I have increased maximumexecution time to almost 30 min, even though it has never taken more then 5 to do it.  Does it always stop on 25, no not on other directories, yes on that particular directory. 

 

Notice in my code I have it loop through the array until the all pictures files have been converted.  What is happening is it exists out of the loop before it finishes.  No errors, nothing breaks, everything worked just fine, it just didnt finish the loop.  If I knew how to move the pointer to start at 25 instead of 1, then perhaps I could see if it finished the rest of the pics.

 

In my other directories I have 31 pics and it works just fine and takes 3.5 minutes to do it.  If I reduce the pics to 25 in that dir it works just fine.  What would make it jump out of the loop.  Ohh, and I have done a count() on the array to be sure how many pics there were to prove it jumped out early. 

 

Thankyou for you help.  I just dont get this one!

Link to comment
https://forums.phpfreaks.com/topic/67113-max-array-size/#findComment-338857
Share on other sites

Are you running the same images in that directory? Could be a particular image is creating the problem (e.g. special character in the name not being handled properly). try adding some code to the page so you can see exactly what is happening at each step. here's a start:

 

Also, I would suggest using if (count($pics))

<?php
  // Creating thumbnails and displaying status
    $picdir='Students/Pics/'.$HTTP_GET_VARS['event']."/";      
    $thumbdir=$picdir;            
    $pics=directory($picdir,"jpg,JPG,JPEG,jpeg,png,PNG");
    $pics=ditchtn($pics,"tn_");
    $pics=ditchtn($pics,"rs_");
    $x=0;

echo "Array size: " . count($pics) . "<br>\n";
echo "<pre>Array Contents:\n";
print_r($pics);
echo "</pre>\n";

    if (count($pics)){
      foreach ($pics as $p)	{
        $x++;
echo "X = " . $x . "<br>\n"
echo "picdir" . $picdir.$p . "<br>\n";
echo "thumbdir" . $thumbdir."rs_".$p . "<br>\n";

        createthumb($picdir.$p,$thumbdir."tn_".$p,125,125,$x);
        createthumb($picdir.$p,$thumbdir."rs_".$p,800,800,$x);}}
php?>

 

if that doesn't uncover anything, then add some debugging to the function code as well.

Link to comment
https://forums.phpfreaks.com/topic/67113-max-array-size/#findComment-338866
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.