Jump to content


Photo

PHP file_exists


  • Please log in to reply
10 replies to this topic

#1 dnienhaus

dnienhaus
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 July 2006 - 08:04 PM

My file_exists always returns false? I know the file exists so what might be the problem?

#2 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 20 July 2006 - 08:06 PM

can you please show us some code?

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 July 2006 - 08:08 PM

WTF! I was replying to this earlier then it disappered. Could you post your code again please.

#4 dnienhaus

dnienhaus
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 July 2006 - 08:09 PM

Heres my variable i want to validate..

$url = "'http://intranet/engineering/drawings/$PARTNUMBER.pdf'";

include ('checkfile.php');

Heres the file_exists code..

<?php
$filename = "$url";

if (file_exists($filename)) 
{}
else 
{$url = "No Drawing";}
?> 


#5 legohead6

legohead6
  • Members
  • PipPipPip
  • Advanced Member
  • 434 posts

Posted 20 July 2006 - 08:14 PM

is that a private bussness network address or sumthin cuz in my browser the link comes up with a dns error

Bad Gateway
The following error occurred:
[code=DNS_HOST_NOT_FOUND] The host name was not found during the DNS lookup. Contact your system administrator if the problem is not found by retrying the URL.[/code]

"Syntax error" .. WHERE THE **** IS IT?!

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 20 July 2006 - 08:15 PM

  • Your $url variable has single quotes within the double.
  • Is $PARTNUMBER defined?
  • Is your PHP version 5.0.0+?
  • Are you sure $filename contains a valid URL? (Did you echo it?)

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 dnienhaus

dnienhaus
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 July 2006 - 08:20 PM

here the full page code :

<?php
$username="root";
$password="";
$database="engineering";


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if(!empty($_POST['search']))
{
echo '<h1>test</h1>';
$query="SELECT * FROM Assembly WHERE PARTNUMBER LIKE '%" . $_POST['search'] . "%'";
$result=mysql_query($query) or die(mysql_error()); 

if($result != false)
{
echo "Here are the results:<br><br>";
echo "<table width=90% align=center border=1><tr>
<td align=center bgcolor=#00FFFF><b>Creation Date</b></td>
<td align=center bgcolor=#00FFFF><b>Creator</b></td>
<td align=center bgcolor=#00FFFF><b>Nomenclature</b></td>
<td align=center bgcolor=#00FFFF><b>OBID</b></td>
<td align=center bgcolor=#00FFFF><b>Part Number</b></td>
<td align=center bgcolor=#00FFFF><b>Part Drawing</b></td>
</tr>";

while ($r = mysql_fetch_array($result)) { // Begin while
$CREATIONDATE = $r["CREATIONDATE"];
$CREATOR = $r["CREATOR"];
$NOMENCLATURE = $r["NOMENCLATURE"];
$OBID = $r["OBID"];
$PARTNUMBER = $r["PARTNUMBER"];
$PARTNUMBER = str_replace('"','',$PARTNUMBER); 

$url = "'http://intranet/engineering/drawings/$PARTNUMBER.pdf'";

include ('checkfile.php');

echo "<tr>
<td><center>$CREATIONDATE</center></td>
<td><center>$CREATOR</center></td>
<td><center>$NOMENCLATURE</center></td>
<td><center>$OBID</center></td>
<td><center><b>$PARTNUMBER</b></center></td>
<td><center>$url</center></td></tr><br><br><hr>";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
} 

?>

its grabbing checkfile.php which is the file_exists function and always returning false.

Partnumber is defined
PHP is 5+
url is valid i can paste it in my browser and open the file and yes it's on a business network.

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 July 2006 - 08:23 PM

You'll want to remove the quotes from the $url variable, so its this:
$url = "http://intranet/engineering/drawings/$PARTNUMBER.pdf";


#9 dnienhaus

dnienhaus
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 July 2006 - 08:25 PM

for some reason when i do that it doesn't parse the variable and the link shows up as "http://intranet/engi...PARTNUMBER.pdf" and not the part #....

#10 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 20 July 2006 - 08:26 PM

Try this:
$url = "http://intranet/engineering/drawings/{$PARTNUMBER}.pdf";


#11 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 20 July 2006 - 08:28 PM

According to the manual, this works with some URL wrappers. I could not get it to work.... There's always:

<?php
	$url = 'http://www.google.com';
	echo $url, '...', fopen($url, 'r') ? 'Yes' : 'No' ;
?>

Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users