Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fopen() and if() question

Status
Not open for further replies.

fluxdemon

MIS
Nov 5, 2002
89
US
I get a "cannot find server" error when I run this. What I intended was to test for each file and create code to display it if it exists.

<?
for($i = 1; $i < 10; ++$i)
{
$tfile = $path.$file.sprintf(&quot;%02d&quot;,$i).$ext;
$nfile = @fopen(&quot;$tfile&quot;,&quot;r&quot;);
if($nfile)
{
print $bcode.$tfile.$ecode.&quot;<br>\n&quot;;
}
}
?>
 
I am assuming that the URLs $tfile is taking work if you plug them into a browser.

If you are using URLs in fopen and getting that error, it could be that DNS isn't set up right on the machine running PHP. It could be that allow_url_fopen in php.ini is set to &quot;off&quot;. It could be that you are trying to use a network protocol PHP doesn't understan.

Have you tried a simple script with a hard-coded URL? Want the best answers? Ask the best questions: TANSTAAFL!
 
I tried to see what the setting was with

<html><body>
<?php phpinfo(); ?>
</body></html>

but the server gives me a &quot;page not found&quot; error.
 
Ooops... I got phpinfo() to work and the allow_url_fopen local and master settings are set to on.
 
The hard coded url works. It seems that
fopen(&quot;hardURL&quot;,&quot;r&quot;);

isnt the same as

$temp = &quot;hardURL&quot;;
fopen(&quot;$temp&quot;,&quot;r&quot;);
or
$temp = &quot;hardURL&quot;;
fopen($temp,&quot;r&quot;);
or
$temp = &quot;hardText&quot;.formatted($genNum).&quot;hardText&quot;;
fopen($temp,&quot;r&quot;);

but $temp = &quot;hardText&quot;.formatted($genNum).&quot;hardText&quot;;
will print the same as a handcoded peice of text.

My guess is fopen has a problem with strings...?
 
It should not make a difference at all.

One thing...when you output the URL to visually inspect it, did you place any kind of delimiters around the output?

For example, performing:

print '&quot;'.$foo.'&quot;';

rather than

print $foo;

It may be that your contatenated string has unprintable characters at its beginning or end. Want the best answers? Ask the best questions: TANSTAAFL!
 
The problem is in your code somewhere, not in the fopen() function.

I recommend that you modify your script to read:

<?
print &quot;<pre>&quot;;
for($i = 1; $i < 10; ++$i)
{
$tfile = $path.$file.sprintf(&quot;%02d&quot;,$i).$ext;
print &quot;|&quot;.$tfile.&quot;|\n&quot;;
/*
$nfile = @fopen(&quot;$tfile&quot;,&quot;r&quot;);
if($nfile)
{
print $bcode.$tfile.$ecode.&quot;<br>\n&quot;;
}
*/
}
?>

And visually inspect all the strings your code is building. View the source of the output in a good text editor if need be. That's where the problem is. Want the best answers? Ask the best questions: TANSTAAFL!
 
Ok. I've done that and pasted the result into TextPad. The output text looks normal. If it is the text that is causing the problem, could a TextPad (unix saved) file on a MS system still have some differences?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top