Jump to content

Open dir problem


diasje

Recommended Posts

Hello, i found one script on the net, to display, the fotos on a folder, but i have to have the script file on that folder.

 

The problem is, i need to have the script file, outside of the images folder.

 

script 1

A script to show the categories of the images folder.

 

htdocs (base dir)

*fotos.php (script file)

**images (images folder)

***img1 (category folder)

***img2 (category folder)

***img3 (category folder)

 

script 2

I need it one script to show the contents of a folder.

 

htdocs (base dir)

*fotos.php (script file)

**images (images folder)

***img1.jpg

***img2.jpg

***img3.jpg

 

Here is the script

 

<?php


$columns     = 5;
$thmb_width  = 120;
$thmb_height = 80;

function resizeImage($originalImage,$toWidth,$toHeight){
    
   
    list($width, $height) = getimagesize($originalImage);
    $xscale=$width/$toWidth;
    $yscale=$height/$toHeight;
    
    
    if ($yscale>$xscale){
        $new_width = round($width * (1/$yscale));
        $new_height = round($height * (1/$yscale));
    }
    else {
        $new_width = round($width * (1/$xscale));
        $new_height = round($height * (1/$xscale));
    }
    
    $imageResized = imagecreatetruecolor($new_width, $new_height);
    $imageTmp     = imagecreatefromjpeg ($originalImage);
    imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    return $imageResized;
} 

function generateThumbnails(){
global $thmb_width,$thmb_height;


if ($handle = opendir("./")) {

	while ($file = readdir($handle))  {

		if (is_file($file)){

      		if (strpos($file,'_th.jpg')){
      			$isThumb = true;
      		} else {
	      		$isThumb = false;
	      	}
      	
      		if (!$isThumb) {
	      		
      			$dirName  = substr($file,0,strpos($file,basename($file)));
      			if (strlen($dirName) < 1) $dirName = '.';
      			$fileName = basename($file);
      			$fileMain = substr($fileName,0,strrpos($fileName,'.'));
      			$extName  = substr($fileName,strrpos($fileName,'.'),
      								strlen($fileName)-strrpos($fileName,'.'));
  					
      			
      			if (($extName == '.jpg') || ($extName == '.jpeg')){
		    		$thmbFile = $dirName.'/'.$fileMain.'_th.jpg';
		    		
		    		if (!file_exists($thmbFile)){
			    		imagejpeg(resizeImage($file,$thmb_width,$thmb_height),$thmbFile,80);
			    	}
				}
      		} 
   		}
   		}
}

}

function getNormalImage($file){
$base = substr($file,0,strrpos($file,'_th.jpg'));
if (file_exists($base.'.jpg')) return $base.'.jpg';
elseif (file_exists($base.'.jpeg')) return $base.'.jpeg';
else return "";
}

function displayPhotos(){
global $columns;

generateThumbnails();
$act = 0;

if ($handle = opendir("./")) {

	while ($file = readdir($handle))  {

		if (is_file($file)){

      		if (strpos($file,'_th.jpg')){
				++$act;
				if ($act > $columns) {
					echo '</tr><tr><td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';	
					$act = 1;
				} else {
					echo '<td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';	
				}
      			
      		}
      	}
	}
}	
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
   <title>Galeria</title>
   <link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
  <div id="main">
    <div class="caption" align="center">Galeria de Fotos</div>
      <table align="center"><tr>     
    		<?php displayPhotos(); ?>
      </table>		
    		
<div id="source">Jednetworks.com</div>
  </div>
</body> 

 

Link to comment
https://forums.phpfreaks.com/topic/49807-open-dir-problem/
Share on other sites

Hi

 

Try changing the line (with 2 occurences)

 

if ($handle = opendir("./")) {

 

to the directory your images are in

 

e.g.

 

if ($handle = opendir("./images")) {

 

or

 

if ($handle = opendir("/mysite/images")) {

 

depending on where the images are.

 

Cheers,

tdw

Link to comment
https://forums.phpfreaks.com/topic/49807-open-dir-problem/#findComment-244311
Share on other sites

I thanks, i bad, i forgot to say that i have tried all this things:

 

"./fotos/"

'./fotos/'

"./fotos"

'./fotos'

"fotos/" and with single quotes

"htdocs/fotos/" and with single quotes

"/htdocs/fotos" and with single quotes

"c:xampp/htdocs/fotos" and with single quotes

 

i have tried with so many diferente things.. i am doing this for 4 hours now...

 

 

Link to comment
https://forums.phpfreaks.com/topic/49807-open-dir-problem/#findComment-244393
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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