PDA

View Full Version : "eregi" function in PHP Photo Album script v2.11 deprecated



Enmanuel Soria
01-25-2012, 06:36 AM
1) Script Title:
PHP Photo Album script v2.11

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

3) Describe problem:
eregi($pattern, $file) function is deprecated and as such this script runs no more, at least it wont on my wamp server with php 5.3.8

ive been thinkering with this one and changed the script to :


<?php

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

function returnimages($dirname="./") {
$pattern="{".$dirname."*.jpg,".$dirname."*.jpeg,".$dirname."*.png,".$dirname."*.gif,".$dirname."*.bmp}";
$files = array();
$curimage=0;
foreach (glob($pattern,GLOB_BRACE) as $file) {
$filedate=date ("M d, Y H:i:s", filemtime($file));
echo " [$curimage, \"$file\", \"$filedate\"],\n";
$curimage++;
}
echo " [\"placeholder\"]\n";

return($files);
}

$photovar=$_GET['id'];

if (!preg_match("/^([a-zA-Z])([a-zA-Z0-9])+$/", $photovar)){
echo "alert(\"Photo Album ID must contain only letters\")";
die();
}
echo "var " . $photovar . "={\n";
echo " baseurl: \"http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER['PHP_SELF']) . "/\",\n";
echo " images: [\n";
returnimages();
echo " ],\n";
echo " desc: []\n";
echo "}\n";
?>

and it works or at least seems like it, but i want to know if theres another way around it, a better one perhaps

btw: i may be mistaken but i downloaded the whole script page and the album in the example doesn't seem to be using the script it has a hardcoded object, at least the one i downloaded do.:confused:

djr33
01-25-2012, 07:00 AM
The preg functions replace the ereg functions. I think what you've done will work (although I haven't tested it).

As for downloading the script, please be more specific. Note that PHP only is visible in the original file (on the server), not if viewed as HTML-- then it is converted to text (without any PHP code) by the server-- that's how PHP works. So if you're using "view source" or "save page as" then you won't see any PHP code. This is one case where you can't build your page based on the source code of the demo page-- you'll need to save the .php page as a file.
(Note: this is why it's in .txt format to download, not .php-- if it was PHP, it would be parsed as PHP, become HTML and lose the PHP code.)

jscheuer1
01-25-2012, 04:38 PM
See also:

http://www.dynamicdrive.com/forums/showthread.php?p=225674#post225674