Jump to content

Recommended Posts

Hi guys!

 

I've been pulling my hair so much I'm going bold now. For some reason this wont work.

 

The error message I get is:

Warning: opendir(/prosjekter/001-vikhammer/thumbs) [function.opendir]: failed to open dir: No such file or directory in G:\www\mms\vis_thumbs.php on line 6

 

The code I use is:

<?php

$vis = $_GET['galleri'];
$galleri = "/prosjekter/".$vis."/thumbs";

if ($handle = opendir($galleri)) {
	$i = 1;
	echo '<table border="0" cellspacing="0" cellpadding="0" width="98%">';
	if ($file !== "." && $file !== "..") {
		while (false !== ($file == $readdir($handle))) {
			echo '<tr><td>';
			echo '<img src="'.$file.'" border="0">';
			$i++;
			if ($i == 6) {
				echo '</td></tr><tr><td>';
				$i = 1;
			}
		}
	}
	closedir($handle);
}

?>

 

I tried copy paste the path printed into the URL, and it went directly into the folder..

 

Thanks In Advance

- Clown

hmm... didnt follow you on that one... so I'ma just post the dir structure...

 

Root

 

- img (dir)

-- "lots of images"

 

- includes (dir)

-- header.php

-- footer.php

 

- prosjekter (dir)

-- 001-vikhammer

--- images

--- thumbs

 

- style (dir)

-- main.css

 

- vis_thumbs.php (file)

 

-------------------------------

did that help you any?

depending on where this file sits, I can't always do "/" to go to the root, so what i have been doing lately, is doing the "../../../" method.

 

$galleri = "../prosjekter/".$vis."/thumbs";

 

 

If you don't know what "../" is well... it does something like this:

 

say your file is sitting here: http://mysite.com/folder1/folder2/folder3/myfile.php

 

and you want to go to a file in folder2, you would do this:

 

folder2 = "../file.php"

folder1 = "../../file.php"

 

for every "../" you move up one directory.

that fixed that problem, but gave me a fatal error... but i fixed that one... but now all I get is a blank page...

 

this is how my codes looks now:

<?php

$vis = $_GET['galleri'];
$galleri = "prosjekter/".$vis."/thumbs";

if ($handle = opendir($galleri)) {
	$i = 1;
	echo '<table border="0" cellspacing="0" cellpadding="0" width="98%">';
	echo "<tr><td>";
	while (false !== ($file == readdir($handle))) {
		/*if ($file !== "." && $file !== "..") {
			echo '<tr><td>';
			echo '<img src="'.$galleri."/".$file.'" border="0">';
			$i++;
			if ($i == 6) {
				echo '</td></tr>';
				$i = 1;
			}
			echo $file;
		}*/
		echo $file;
		echo "test";
	}
	echo "</td></tr>";
	echo "</table>";
	closedir($handle);
}

?>

Try this:

 

I didn't test it, so there may be a few bugs

<?php
$vis = $_GET['galleri'];
$galleri = "prosjekter/".$vis."/thumbs";
if(is_dir($galleri)){
echo '<table border="0" cellspacing="0" cellpadding="0" width="98%">';
foreach (glob($galleri.'/*.jpg') as $file) {
	echo '<tr><td>';
	echo '<img src="'.$file.'" border="0">';
	echo '</td></tr>';
	echo $file;
}
echo $file;
echo "test";
}
?>

Did you get my modifications to the code? I changed it, you may have copied it before i modified it.

 

 

so try this:

 

<?php
$vis = $_GET['galleri'];
$galleri = "prosjekter/".$vis."/thumbs";
if(is_dir($galleri)){
echo '<table border="0" cellspacing="0" cellpadding="0" width="98%">';
foreach (glob($galleri.'/*.jpg') as $file) {
	echo '<tr><td>';
	echo '<img src="'.$file.'" border="0">';
	echo '</td></tr>';
	echo $file;
}
echo $file;
echo "test";
}
?>

this was the result

 

Array ( [0] => prosjekter/001-vikhammer/thumbs/S5025782.JPG [1] => prosjekter/001-vikhammer/thumbs/S5025783.JPG [2] => prosjekter/001-vikhammer/thumbs/S5025784.JPG [3] => prosjekter/001-vikhammer/thumbs/S5025785.JPG [4] => prosjekter/001-vikhammer/thumbs/S5025786.JPG [5] => prosjekter/001-vikhammer/thumbs/S5025787.JPG [6] => prosjekter/001-vikhammer/thumbs/S5025788.JPG [7] => prosjekter/001-vikhammer/thumbs/S5025789.JPG [8] => prosjekter/001-vikhammer/thumbs/S5025790.JPG [9] => prosjekter/001-vikhammer/thumbs/S5025791.JPG [10] => prosjekter/001-vikhammer/thumbs/S5025792.JPG [11] => prosjekter/001-vikhammer/thumbs/S5025793.JPG [12] => prosjekter/001-vikhammer/thumbs/S5025794.JPG [13] => prosjekter/001-vikhammer/thumbs/S5025795.JPG [14] => prosjekter/001-vikhammer/thumbs/S5025796.JPG [15] => prosjekter/001-vikhammer/thumbs/S5025797.JPG [16] => prosjekter/001-vikhammer/thumbs/S5025798.JPG [17] => prosjekter/001-vikhammer/thumbs/S5025799.JPG [18] => prosjekter/001-vikhammer/thumbs/S5025800.JPG [19] => prosjekter/001-vikhammer/thumbs/S5025818.JPG [20] => prosjekter/001-vikhammer/thumbs/S5025819.JPG [21] => prosjekter/001-vikhammer/thumbs/Thumbs.db )

Lets find out if it is going into that if statement i made.

 

<?php
$vis = $_GET['galleri'];
$galleri = "prosjekter/".$vis."/thumbs";
if(is_dir($galleri)){
echo 'Directory '.$galleri.' DOES EXIST!!!';
}else{
echo 'Directory '.$galleri.' DOES NOT EXIST ';
}
?>

thanks Little Guy... just modified some of your codes and now it works perfect...

 

the final result:

<?php
$vis = $_GET['galleri'];
$galleri = "prosjekter/".$vis."/thumbs";
$files = glob($galleri.'/*');

echo '<table border="0" cellspacing="2" cellpadding="0" width="98%">';
echo '<tr>';
$i=1;
foreach ($files as $file) {
	$ext = explode(".", $file);
	if ($ext[1] == "JPG") {
		echo '<td><img src="'.$file.'" border="0"></td>';
		$i++;
		if ($i == "6") {
			echo '</tr><tr>';
			$i=1;
		}
	}
}
echo '</tr>';
echo '</table>';

?>

This works on my server:

<?php
$vis = $_GET['galleri'];
$galleri = "prosjekter/".$vis."/thumbs";
if(is_dir($galleri)){
echo '<table border="0" cellspacing="0" cellpadding="0" width="98%">';
foreach (glob($galleri.'/*') as $file) {
	echo '<tr><td>';
	echo '<img src="'.$file.'" border="0">';
	echo '</td></tr>';
	echo $file;
}
echo $file;
echo "test";
}
?>

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.