Jump to content

Check a file exists without running it


Zephni

Recommended Posts

In my situation I need to check that a php file exists, but I do not want to run any code in that script yet.

 

I have tried the PHP is_file: http://php.net/manual/en/function.is-file.php and the file_exists function: http://php.net/manual/en/function.file-exists.php

 

But both actually run the file. I can tell because of using sessions to test it in the file itself.

 

Is there any way around this?

 

Thanks in advance.

Link to comment
Share on other sites

the only way those two functions would run the php code in the file being tested is if you are using a URL to reference the file, instead of a file system path.

 

if these .php files are on the same server as your php script that is testing if they exist, you should be using a file system path.

 

i've got to ask, if this is your code, why do you need to test if a .php file exists? you should already know if it does.

Link to comment
Share on other sites

I have been working on a frame work type thing: (http://zephni.com/phpzevelop/howto and GitHub https://github.com/Zephni/PHPZevelop) it needs to check for files (pages) before producing them, if the page does not exist and the page isn't set to receive parameters through the URL then it needs to set the default 404 page instead of the page that does exist. It's hard to explain but I have changed the way it works now so it uses try catch statements to check if the files exist instead of using file_exists methods.

Edited by Zephni
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.