473,382 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Some difficulty with file_exists

So I wrote a script to run via crontab but when it tries to check
whether a file exists like below:

if (!file_exists("settings.ini"))
return false;

it checks whether the file exists in $HOME not in /home/user/files/
scripts/ where the original file is been executed from:

00 20 * * 1 /usr/local/bin/php /home/user/files/scripts/check.php /
dev/null 2>&1

Why is that?

Apr 25 '07 #1
2 1958
Rik
ro*********@googlemail.com wrote:
So I wrote a script to run via crontab but when it tries to check
whether a file exists like below:

if (!file_exists("settings.ini"))
return false;

it checks whether the file exists in $HOME not in /home/user/files/
scripts/ where the original file is been executed from:

00 20 * * 1 /usr/local/bin/php /home/user/files/scripts/check.php /
dev/null 2>&1

Why is that?
Because you use the CLI, not the (web)server variant? The current
working directory is the directory from which /usr/local/bin/php is invoked.
So, for instance on the `doze box here:

-- C:\cwd.php ---
echo getcwd();
--------------
C:\>"C:\PHP\php.exe" "C:\cwd.php"
C:\

C:\>cd FOO

C:\FOO>"C:\PHP\php.exe" "C:\cwd.php"
C:\FOO

If it's terribly important that the working directory is the same as
where your file resides you can add something like this to it:

chdir(dirname(__FILE__));
HTH,
--
Rik Wasmus

Estimated date being able to walk again: 01-05-2007.
Less then a week, hurray!
Apr 25 '07 #2
ro*********@googlemail.com wrote:
So I wrote a script to run via crontab but when it tries to check
whether a file exists like below:

if (!file_exists("settings.ini"))
return false;

it checks whether the file exists in $HOME not in /home/user/files/
scripts/ where the original file is been executed from:

00 20 * * 1 /usr/local/bin/php /home/user/files/scripts/check.php /
dev/null 2>&1

Why is that?
When using as CLI program, the ./ is the location from where the file is
executed, in your example it's the cron users home directory that would most
likely be ./, so the solution for your problem is to use absolute path.

if (!file_exists("home/user/files/scripts/settings.ini"))
return false;

Things are different if you execute the script via a web server, but absolut
paths will always work.

--

//Aho
Apr 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andrew Crowe | last post by:
Hi guys, I've created this little function to check whether a user has uploaded a file with the same name as an existing file, and if so rename it to file-1.jpg, file-2.jpg etc. ...
1
by: Hinrich Specht | last post by:
Hello, I have a problem using file_exists. I want to use file_exists to dertermine if a product-image is available or not to show either the product-image or a standard-image. This is the code:...
5
by: lkrubner | last post by:
I've written some template code and one thing I'm trying to protect against is references to images that don't exist. Because users have the ability to muck around with the templates after...
3
by: Chris Saunders | last post by:
I am attempting to write and interface from another language to some C code. I am having some difficulty interpreting a declaration. int (*SSL_CTX_get_verify_callback(SSL_CTX...
7
by: =?Utf-8?B?SmVmZkRvdE5ldA==?= | last post by:
I have an asp.net application using a multi-page wizard control that grabs user selected files from a database and allows the user to configure parameters using controls on the wizard pages. The...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
20
by: Bob Sanderson | last post by:
This is my code: if (file_exists($Fname)) { echo "<td>$Fname exists</td>"; } else { echo "<td>$Fname does not exist</td>"; } $Fname is the full path to the file I'm trying to verify. When I...
1
by: Kevin Walzer | last post by:
I'm trying to create a custom Tkinter widget class, and I'm having some difficulty getting it set up properly. The class is called MacToolbar, saved in its own module MacToolbar.py, and imported...
3
by: rickcasey | last post by:
I'm using PHP 4.4.4-8 on Debian Linux on a low traffic site, and need to detect if a file exists, and if so, unlink it. I am mystified as to why the file_exists() function does not work in one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.