In your output file, the error on fopen is showing a newline after the
file name. When you use fgets() to get the filenames, it includes the
newline from the file.
This will get rid of the newline character. The trim function removes
any whitespace around a string.
$mainfileline = trim(fgets($mainfile, 1024));
Michael Sullivan wrote:
>My wife and I take a lot of pictures with our digital camera. I have a
>Linux web server with a static IP address and we have a digital photo
>page. It consists of a photo index displaying 100x100 photos organized
>into tables by date. If someone clicks on one of the small pictures it
>loads the full size picture. Until recently I had been using a program
>I wrote in Visual Basic 6 to generate the photoindex.html page and then
>uploading it to my server box. My computer is not doing well in Windows
>anymore and I'd prefer to use Linux for as much as possible, so I've
>been trying to convert my VB program into PHP. I thought I had the
>script right, but I keep having problems. I fixed what errors I could,
>but then attempting to load the page kept overloading mozilla. I wrote
>to one of my Linux lists about this problem and someone suggested that I
>use wget from a terminal to wget the file from the web server and look
>at it. I did this and what I saw disturbed me.
>
>My VB program (and now my script) was written to read a master list
>called "list.txt". This list.txt would contain the filenames of other
>lists. The "sub-lists" contained filenames of images that the program
>would use to construct the html page that it would return to the
>requesting browser. My VB program worked fine. However my PHP program
>not so good.
>
>Here is the code for my PHP script:
>
><?
>
>function newTable($filename)
>{
> $count = 0;
> $strDir = substr($fileName, 24, 6);
> $strMonth = substr($strDir, 0, 2);
> $strDay = substr($strDir, 3, 2);
> $len = strlen($strDir);
> $strYear = substr($strDir, ($len - 2), 2);
>
> $subfile = fopen("$filename", 'r');
>
> while (!feof($subfile))
> {
> $subfileline = fgets($subfile, 1024);
> $count++;
> }
> fclose($subfile);
>
> $subfile = fopen("$filename", 'r');
>
> print " <center>\n";
> print " <h3>Added $strMonth/$strDay/$strYear</h3>\n";
> print " <br><br>\n";
> print " <table cellspaceing='0' cellpadding='4'>\n";
>
> While (!feof($subfile))
> {
> While ($count > 5)
> {
> print " <tr>\n";
> for ($x = 0; $x < 4; $x++)
> {
> $subline = fgets($subfile, 1024);
> $intAltLen = strlen($subline) - 4;
> $strAlt = substr($subline, 0, $intAltLen);
> $strLink = "mini-$subline";
> print " <td align='center' valign='top'>\n";
> print " <a href='$strDir/$subline>\n";
> print " <img src='$strDir/mini/$strLink' width=100
>height=100 alt='$strAlt>\n";
> print " </a>\n";
> print " </td>\n";
> }
> print " </tr>\n";
> print "<!- End group-->\n";
> print "\n";
> $count -= 5;
> }
> print "<tr>\n";
> for ($x = 0; $x < $count - 1; $x++)
> {
> $subline = fgets($subfile, 1024);
> $intAltLen = strlen($subline) - 4;
> $strAlt = substr($subline, 0, $intAltLen);
> $strLink = "mini-$subline";
> print " <td align='center'>\n";
> print " <a href='$strDir/$subline>\n";
> print " <img src='$strDir/mini/$strLink' width=100
>height=100 alt='$strAlt>\n";
> print " </a>\n";
> print " </td>\n";
> }
> print "</tr>\n";
> }
> print " </table></center>\n";
> print "<br><br>\n";
> fclose($subfile);
>}
>$title = "My Pictures"; //<title> of page
>$bgcolor = "#000000"; //<bgcolor> of page
>$text = "#FFFFFF"; //<text> of page
>
>print "<html>\n";
>print " <head>\n";
>print " <title>$title</tite>\n";
>print " </head>\n";
>print "\n";
>print "<body bgcolor='$bgcolor' text='$text'>\n";
>print "\n";
>print "<center><h1>$title</h1></center>\n";
>
>$mainfile = fopen("list.txt", 'r');
>while (!feof($mainfile))
>{
> $mainfileline = fgets($mainfile, 1024);
> newTable($mainfileline);
>}
>fclose($mainfile);
>
>print " </body>\n";
>print "</html>\n";
>?>
>
>This script sits in /home/michael/webspace/html/camera along with all
>the list files. Here is the contents of list.txt:
>
>[EMAIL PROTECTED] camera $ cat list.txt
>list020705.txt
>list011305.txt
>list010105.txt
>list122404.txt
>list112504.txt
>list110804.txt
>list110604.txt
>list102304.txt
>list101004.txt
>list100304.txt
>
>Here is the contents of list020705.txt:
>
>[EMAIL PROTECTED] camera $ cat list020705.txt
>Amy's Birthday Cake.JPG
>Feli - How Do I Turn The Water On.JPG
>Feli - Lazy Day.JPG
>Feli - Whazzat.JPG
>When Teddy Bears Attack.JPG
>
>
>There's not a permissions problem - everything in the camera directory
>is chmod'd 755. The apache web server
>sees /home/michael/webspace/html/camera/picindex.php as
>http://192.168.1.2/members/michael/camera/picindex.php . When I wget
>the file the the file size is 88MB (very disturbing.) The first few
>lines of the file are:
>
>[EMAIL PROTECTED] michael $ cat picindex.php | more
><html>
> <head>
> <title>My Pictures</tite>
> </head>
>
><body bgcolor='#000000' text='#FFFFFF'>
>
><center><h1>My Pictures</h1></center>
><br />
><b>Warning</b>: fopen(list020705.txt
>): failed to open stream: No such file or directory in
><b>/home/michael/webspace/html/camera/picindex.php</b> on line
><b>12</b><br />
><br />
><b>Warning</b>: feof(): supplied argument is not a valid stream
>resource in <b>/home/michael/webspace/html/camera/picindex.php</b> on
>line <b>14</b><br />
><br />
><b>Warning</b>: fgets(): supplied argument is not a valid stream
>resource in <b>/home/michael/webspace/html/camera/picindex.php</b> on
>line <b>16</b><br />
><br />
><b>Warning</b>: feof(): supplied argument is not a valid stream
>resource in <b>/home/michael/webspace/html/camera/picindex.php</b> on
>line <b>14</b><br />
><br />
><b>Warning</b>: fgets(): supplied argument is not a valid stream
>resource in <b>/home/michael/webspace/html/camera/picindex.php</b> on
>line <b>16</b><br />
><br />
><b>Warning</b>: feof(): supplied argument is not a valid stream
>resource in <b>/home/micha
>
>The entire file is full of lines like the ones above. The list files
>exist and it's not a permissions problem:
>
>[EMAIL PROTECTED] camera $ ls -l list*
>-rwxr-xr-x 1 michael users 160 Jun 8 19:29 list.txt
>-rwxr-xr-x 1 michael users 133 Feb 7 16:47 list010105.txt
>-rwxr-xr-x 1 michael users 310 Feb 7 16:47 list011305.txt
>-rwxr-xr-x 1 michael users 134 Feb 7 16:47 list020705.txt
>-rwxr-xr-x 1 michael users 2294 Feb 7 16:47 list100304.txt
>-rwxr-xr-x 1 michael users 377 Feb 7 16:47 list101004.txt
>-rwxr-xr-x 1 michael users 212 Feb 7 16:47 list102304.txt
>-rwxr-xr-x 1 michael users 238 Feb 7 16:47 list110604.txt
>-rwxr-xr-x 1 michael users 440 Feb 7 16:47 list110804.txt
>-rwxr-xr-x 1 michael users 428 Feb 7 16:47 list112004.txt
>-rwxr-xr-x 1 michael users 260 Feb 7 16:47 list112504.txt
>-rwxr-xr-x 1 michael users 307 Feb 7 16:47 list122404.txt
>
>In my script I think I have double quotes in all the right places, yet
>the output file doesn't show them in the script. Where am I messing up
>and how do I make this right? Our digital camera died back in February
>and we can finally afford to replace it with a new one. It should be in
>any day now and I'd like to have this script ready by then because we
>just got a new kitten (lots of photo opportunities!) Please help!
>
>
>
>Community email addresses:
> Post message: [email protected]
> Subscribe: [EMAIL PROTECTED]
> Unsubscribe: [EMAIL PROTECTED]
> List owner: [EMAIL PROTECTED]
>
>Shortcut URL to this page:
> http://groups.yahoo.com/group/php-list
>Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
>
--
---------------------------------
* Brandon Smith
* programmer / web designer
* http://sproutworks.com
Community email addresses:
Post message: [email protected]
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/