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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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'; ?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.