Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6939333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:36:34+00:00 2026-05-27T12:36:34+00:00

I have a folder uploads in the root folder. There is another folder A

  • 0

I have a folder uploads in the root folder. There is another folder A in the root, and contains a PHP file. I have the following code in the PHP file:

$imgpath = '/uploads/' . $filename;
echo '<img src="' . $imgpath . '" />';
echo (file_exists($imgpath))?'true':'false';

It will show the image, so the file exists, but file_exists shows false.

If I change '/uploads/' to '../uploads/', it will show the image and file_exists shows true. Even if there is no image, file_exists always shows true.

What is the problem?

* Update *

I tried echo dirname(__FILE__);. It shows /....../A, the uploads folder is located at /....../uploads. Moreover, I have another similar PHP file in folder /....../m/A. So I need some kind of universal path. How to get the root path, i.e., /....../?

I also tried $_SERVER['DOCUMENT_ROOT'], but the image cannot be shown, although the path is 100% correct.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:36:35+00:00Added an answer on May 27, 2026 at 12:36 pm

    To avoid problems, it’s easiest to use an absolute path with file_exists(). The system root / is not the same as your web root (e.g.,) /var/www

    Try

    # /var/www/A/script.php
    $imgpath = '/uploads/' . $filename;
    
    # check in /var/www/uploads/filename
    if( file_exists(dirname(__FILE__) . '/..' . $imgpath) ) {
        echo '<img src="' . $imgpath . '" />';
    }
    

    EDIT for PHP >= 5.3

    $path = "/uploads/${filename}";
    
    if (file_exists(sprinf("%s/..%s", __DIR__, $path)) {
      echo "<img src=\"{$path}\">;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have folder home/admin. In this folder there is index.php. When i access to
I have a PHP script that processes file uploads. The script tries to organise
I have created an uploads folder in the CodeIgniter root, that accepts all the
I have the following code for uploading a folder form local storage to blob
I have a set of images in a folder call 'uploads/', all the files
I have a folder, c:\websites\test , and it contains folders and files that were
I have a folder FolderA which contains three sub-folders: foldera1 foldera2 and foldera3 I
I'm trying to write to an XML file in the uploads folder in my
I have some client side code that uploads an Outlook email to a document
I have an array of folders/files that looks like this: Array ( [Root Folder

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.