Jump to content

Before I write the script, how much resources would this take?


suttercain

Recommended Posts

Hi guys,

 

I am debating on having a script which checks a directory for a specific file. If the file is found, a URL to the file will be provided. If no file is found, there is no URL to go to so no link. My concern though is with resources. I do a mysql_query which sometimes renders hundreds of results. I would need this script to run for each specific result and than loop through the directory.

 

Do you think this would use to much resources or no?

 

Thanks for your opinions.

I do the mysql query and create a while loop to display the results. Within the while loop I foreach loop that looks like this:

 

foreach (glob("$dir/".$row['filename'].".pdf", GLOB_BRACE) as $file)

 

If the file matches the sql result (Filename === Filename) echo <a href="#"></a> If no file matches no link.

 

 

Because I am a jackass who didn't even know a function like that existed :)

 

Thanks. You just saved me a lot of work :)

 

Lol, you knew about glob(), but not file_exists()?  You'd be surprised at how often it's the other way around.  Anyway, glad I could help.

Thanks again for getting back to me with this. I am trying the file_exists function and it's returning FALSE even though the file does exist. I checked to ensure safe_mode is off and it is. Any other reason this may be kicking back FALSE instead of true?

 

Thanks again.

I have it set up like this, because the directory location depends on some of the mysql results:

 

<?php
//This is in the WHILE Loop used to mysql_fetch_array()
$filename = 'http://www.domain.com/msprog/offroad/cert/eo/'.$row['engine_year'].'/ofci/'.$row['engine_executive_order'].'.pdf';
if (file_exists($filename)) {
  $engineFamilyName = "<a href=".$filename.">".$row['engine_family_name']."</a>";
} else {
  $engineFamilyName = $row['engine_family_name'];
}

echo $engineFamilyName;

?>

 

When I echo $filename I get the correct link and am able to go to it via the URL.

Yeah the directories are horrible (not in my control) and they will always be like this. So the file_exists will nto work with an absolute path? I should instead do ..../../../msprog/offroad/cert/eo/'.$row['engine_year'].'/ofci/'.$row['engine_executive_order'].'.pdf'; ?

Yeah the directories are horrible (not in my control) and they will always be like this. So the file_exists will nto work with an absolute path? I should instead do ..../../../msprog/offroad/cert/eo/'.$row['engine_year'].'/ofci/'.$row['engine_executive_order'].'.pdf'; ?

 

Wait, are they on your site?  file_exists() doesn't work with URLs, but it works with relative or absolute filesystem paths.

I'm still not able to get this file_exists function to work for me. Here is the code I am using...

 

<?php
$filename = '/msprog/offroad/cert/eo/'.$row['engine_year'].'/ofci/'.$row['engine_executive_order'].'.pdf';
  if (file_exists($filename)) {
    $engineFamilyName = "<a href=".$filename.">".$row['engine_family_name']."</a>";
  } else {
    $engineFamilyName = $row['engine_family_name']; //This is what it echos even though a file is there.
  }

echo $engineFamilyName . "<br />";

echo "<a href='$filename'>$filename</a>"; //I check the file path and it works. The link goes to the pdf document.
?>

 

Any help would be greatly appreciated. Thanks.

Archived

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

×
×
  • Create New...

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.