Jump to content

Archived

This topic is now archived and is closed to further replies.

dnienhaus

PHP file_exists

Recommended Posts

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

Share this post


Link to post
Share on other sites
Heres my variable i want to validate..

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

include ('checkfile.php');[/code]

Heres the file_exists code..

[code]<?php
$filename = "$url";

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

Share this post


Link to post
Share on other sites
is that a private bussness network address or sumthin cuz in my browser the link comes up with a dns error

[code]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][/code]

Share this post


Link to post
Share on other sites
[list]
[*]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?)
[/list]

Share this post


Link to post
Share on other sites
here the full page code :

[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";
}

?>[/code]

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.

Share this post


Link to post
Share on other sites
You'll want to remove the quotes from the $url variable, so its this:
[code]$url = "http://intranet/engineering/drawings/$PARTNUMBER.pdf";[/code]

Share this post


Link to post
Share on other sites
for some reason when i do that it doesn't parse the variable and the link shows up as "http://intranet/engineering/drawings/$PARTNUMBER.pdf" and not the part #....

Share this post


Link to post
Share on other sites
Try this:
[code]$url = "http://intranet/engineering/drawings/{$PARTNUMBER}.pdf";[/code]

Share this post


Link to post
Share on other sites
According to the manual, this works with [i]some[/i] URL wrappers. I could not get it to work.... There's always:

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.