473,231 Members | 1,539 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,231 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 2256
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 "";
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.