473,396 Members | 1,866 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,396 software developers and data experts.

Problem with file_exists

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:

$image = "../../artimages/".$item_code.".jpg";

if (file_exists($image))
$item_detail_image = $image;
else
$item_detail_image = $toshopdata."img/no_image.jpg";

The Problem: If I use "../../artimages/".$item_code.".jpg" as image
src, the image is displayed correctly...meaning the file does exist in
the given path.
The file_exists - method on the other hand always returns false, and I
don´t know why. Can anyone help?
Thanks in advance,

Hinrich Specht
Jul 17 '05 #1
1 2265
Hinrich Specht wrote:

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:

$image = "../../artimages/".$item_code.".jpg";

if (file_exists($image))
$item_detail_image = $image;
else
$item_detail_image = $toshopdata."img/no_image.jpg";

The Problem: If I use "../../artimages/".$item_code.".jpg" as image
src, the image is displayed correctly...meaning the file does exist in
the given path.
The file_exists - method on the other hand always returns false, and I
don´t know why. Can anyone help?


Maybe the url path is different from the file path? Is the directory
"artimages" actually located in the grandparent directory of the directory from
which the script is being called? Usually that's the case, but it might be
different depending on how you're implementing your code above (like if the code
above sits in an admin directory and creates static HTML or something) or if
you're using a <BASE HREF=""> tag.

Maybe try replace file_exists with fopen to generate an error (make sure you
have errors turned on). It should tell you that the file won't open and give
you the absolute path to it. Take a look at that path and I'll bet you'll see
what's wrong...

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #2

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

Similar topics

0
by: Irvin Amoraal | last post by:
Well, I must say that I am new to working with FTP and am having problems despite the good help I have recieved. I have been working with code supplied by Janwillem Borleffs and have been able to...
2
by: Ian Hardcastle | last post by:
I am creating a php script that I can call from a delphi program, this itself is easy as I have already done this. The problem lies within the php script, here is the code that DOESN'T work: <?...
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. ...
10
by: Google Mike | last post by:
{NOTE: I have PHP 4.2.2 for RH9 Linux.} Anyone have a better file_exists() out there? Even if you use shell out tricks with Linux using the `command` trick, I'd be interested to see what you...
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...
4
by: dchaffin | last post by:
I'm having a problem using file_exists with an absolute path and I can not figure out why. I tried the exact example that is on www.php.net ... <?php $filename = '/path/to/foo.txt'; if...
6
by: +86 | last post by:
i encountered this problem: "include('inc.php')" will work problely but "include('./inc.php') doesn't work .. both file_exists('inc.php') or file_exists('./inc.php') didn't return the right...
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...
14
by: shror | last post by:
Hi every body, am trying to create a php script that get a daily picture but am having a problem with that, here is the code am using: <?php $date = date("Y-m-d"); echo "";
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.