Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2006, 01:57 PM
Registered User
 
Join Date: Mar 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default I got a problem in PHP. Please help me!!!!!

This is my code.

<?
// image index
// generates an index file containing all images in a particular directory
//point to whatever directory you wish to index.
//index will be written to this directory as imageIndex.html
$dirName = "mm";
$dp = opendir($dirName);
chdir($dirName);
//add all files in directory to $theFiles array
while ($currentFile !== FALSE){
$currentFile = readDir($dp);
$theFiles[] = $currentFile;
} // end while
//extract gif and jpg images
$imageFiles = preg_grep("/jpg$|gif$/", $theFiles);
$output = "";
foreach ($imageFiles as $currentFile){
$output .= <<<HERE
<a href = $dirName/$currentFile>
    <img src = "$dirName/$currentFile"
height = 50
width = 50>
</a>
HERE;
} // end foreach
//save the index to the local file system
$fp = fopen("imageIndex.html", "w");
fputs ($fp, $output);
fclose($fp);
//readFile("imageIndex.html");


print "<a href = imageList.php>image index</a>\n";


?>




OUT PUT

Notice: Undefined variable: currentFile in c:\inetpub\wwwroot\thaiseek\imageIndex.php on line 10
image index


The program works fine but


What's wrong on line 10 ?

Why it shows "Notice: Undefined variable" ?

Thank You.
 
Old December 23rd, 2006, 08:36 AM
Authorized User
 
Join Date: Oct 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello aeroboy,

  declaire first the variable before using it try like this:

<?
// image index
// generates an index file containing all images in a particular directory
//point to whatever directory you wish to index.
//index will be written to this directory as imageIndex.html
$dirName = "mm";
$dp = opendir($dirName);
chdir($dirName);
//add all files in directory to $theFiles array
$currentFile = readDir($dp);
while ($currentFile !== FALSE){

$theFiles[] = $currentFile;
} // end while
//extract gif and jpg images
$imageFiles = preg_grep("/jpg$|gif$/", $theFiles);
$output = "";
foreach ($imageFiles as $currentFile){
$output .= <<<HERE
<a href = $dirName/$currentFile>
    <img src = "$dirName/$currentFile"
height = 50
width = 50>
</a>
HERE;
} // end foreach
//save the index to the local file system
$fp = fopen("imageIndex.html", "w");
fputs ($fp, $output);
fclose($fp);
//readFile("imageIndex.html");


print "<a href = imageList.php>image index</a>\n";
?>

______________________________________
.::If you quit you loss, If you survive you win::.

.::JHANNY::.


 
Old December 26th, 2006, 11:45 PM
Authorized User
 
Join Date: Dec 2006
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to paagle
Default

which versions are these? It depends on that too..........
As far as i think the above post has given u the reply

---
Paagle
TEAM LEADER-Team Xuberance(http://www.xuberance.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with PHP and IE phpcoder Forum and Wrox.com Feedback 4 September 10th, 2011 07:07 AM
problem in php webphp SQL Server 2000 0 February 8th, 2005 03:52 AM
I need some help on this php problem. major dynamic123 Pro PHP 6 March 5th, 2004 05:49 PM
Problem with PHP and IE phpcoder PHP Databases 1 January 30th, 2004 06:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.