PDA

View Full Version : PHP Photo Album Script Error - document.getElementById



caha97
09-23-2007, 04:27 AM
1) Script Title: DD PHP Photo Album script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex4/php-photoalbum.htm

3) Describe problem: I am receive the following error when loading the page document.getElementById(...) is null or not an object

test page: www.jrcoyotes97.com/test2.html

There are 4 images in the /photos folder a.jpg, b.jpg, c.jpg, d.jpg
The getpics.php is also in the /photes folder. I double checked to make sure that the get.pics.php against the one that I downloaded from the script page.

jscheuer1
09-23-2007, 06:16 AM
This is the output of your http://www.jrcoyotes97.com/photos/getpics.php file:


var galleryarray=new Array();

Obviously, either there are no images in that folder or your host's PHP interpreter needs different code in order to retrieve them.

In the first case, upload the images to that folder, in the second case, determine the proper PHP syntax for your server. Common problems with getpics.php are that many servers prefer (additions red):


<?php
Header("content-type: application/x-javascript");

function returnimages($dirname="./") {
$pattern="\.(jpg|jpeg|png|gif|bmp)$";
$files = array();
$curimage=0;
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle))){
if(eregi($pattern, $file)){
$filedate=date ("M d, Y H:i:s", filemtime($file));
echo 'galleryarray[' . $curimage .']=["' . $file . '", "'.$filedate.'"];' . "\n";
$curimage++;
}
}

closedir($handle);
}
return($files);
}

echo "var galleryarray=new Array();" . "\n";
returnimages();
?>

caha97
09-23-2007, 08:32 PM
I double checked the photos and they are in the folder with getpics.php.

I also uploaded getpics.php with the changes you suggested but I am still getting the same error.

Any other thoughts?

BTW the host is Godaddy.com.

jscheuer1
09-23-2007, 10:39 PM
The output of your getpics.php file is still just:


var galleryarray=new Array();

Are you sure there are any images in the http://www.jrcoyotes97.com/photos/ folder? If so, what are some of their filenames? Make sure they are valid image files and that the extensions are lower case and one of the following:

.jpg
.jpeg
.png
.gif
.bmp

caha97
09-24-2007, 12:03 AM
Thanks for the response.

I created 4 photos just for testing: photo1.jpeg, photo2.gif, photo3.png, and photo4.jpg.

I just updated the HTML so the images were hardcoded to come up when the page is opened at the end of <body> just to be sure that they would come up. I hardcoded the absolute image path "img src = http://www.jrcoyotes97.com/photos/photo1.jpeg"

I am starting to think there may be a problem with the $dirname ="./" may not be resulting in the proper path.

jscheuer1
09-24-2007, 02:00 AM
I see that at least one of your images is in the folder, now that you've given me the filenames. Your assumption seems reasonable. We can also infer that the server is PHP capable because, otherwise it wouldn't even have outputted:


var galleryarray=new Array();

which is still all that it is doing. There may be restrictions set by your host upon what it will allow PHP to do. If your host has decent support, ask them why they might think it isn't working and/or go over your host's online documentation to see if there are any restrictions upon what PHP may be used for.

It still might be a syntax problem though. Not all PHP hosts accept the same syntax. The syntax used in Dynamic Drive's getpics.php file is simply the most commonly acceptable syntax. Also, the version of PHP that your host has installed may not be recent enough.

caha97
09-24-2007, 03:25 AM
I ran the following on the site.
<?php
phpinfo();
?>

When looking at the configuration for the PHP Core, I noticed that for the disable_function directive the following commands are listed opendir, closedir, and readdir. This is the problem since getpics.php uses these functions to read the files.

Apparently, Godaddy.com only enables these when you purchase a dedicated server account.

John, thanks for your support and patience on this.