file_exists() not working codeigniter

php file_exists not working
php file_exists url
php check if file exists before file_get_contents
codeigniter check view file exists
file_exists in codeigniter
file_exists in php
php file does not exist
php create file if not exists

I am working with codeigniter. I want to display images but if some image is not exist it should show image-not-found-medium.jpg which is dummy image..

below is my code

    $image_path_medium = site_url('assets/images-products/medium');
    $image_not_found_medium =  $image_path_medium . "/" . "image-not-found-medium.jpg";
    $image_name_with_path = $image_path_medium . "/" . $home_technology[$key]->product_sku . "-" . "a" . "-medium.jpg";

    if (file_exists($image_name_with_path)) {
        echo $image_name_with_path;
    } else {
        echo $image_not_found_medium;

but it always shows $image_not_found_medium i think there is problem with my if condition. Please help.

    $image_path_medium = site_url('assets/images-products/medium');
    $image_not_found_medium =  $image_path_medium . "/" . "image-not-found-medium.jpg";
    $image_name_with_path = $image_path_medium . "/" . $home_technology[$key]->product_sku . "-" . "a" . "-medium.jpg";//this is your image url
    $image_file_path=FCPATH.'assets/images-products/medium'. $home_technology[$key]->product_sku . "-" . "a" . "-medium.jpg";//this is your file path

   if (file_exists($image_file_path)) //file_exists of a url returns false.It should be real file path
       echo $image_name_with_path;
      echo $image_not_found_medium;

file_exists() function is not working in CI Helper, I downloaded the latest version of Codeigniter (3.1.9) about a week ago. When ever I try to use the php file_exists() function to check if a image� That does not work as it redirects whether or not the file exists. If the file is not found then it creates the 'chris/john/chat' & 'john/chris/chat' Controllers & view pages. The conversations can begin. That part I have working but it needs attention particularly in the variables for example.

You are using absolute path for file existence which is wrong. You have to use real path because the file_exists() function checks whether or not a file or directory exists on the current server.

If your assets folder is placed in root then just use getcwd() - Gets the current working directory as

$image_path_medium = getcwd().'assets/images-products/medium';

Otherwise give the proper path to the assets folder like

$image_path_medium = getcwd().'application/views/assets/images-products/medium';

PHP file_exists() function not working Codeigniter 3.1.9, Re: [Solved] CodeIgniter file_exists not working. Posted 15 July 2014 - 04:51 PM. Also, what is base_url() showing? Was This Post Helpful? 0. You create a new File instance by passing in the path to the file in the constructor. By default, the file does not need to exist. However, you can pass an additional argument of “true” to check that the file exists and throw FileNotFoundException () if it does not. $file = new \CodeIgniter\Files\File($path);

Instead of file_exists() prefer is_file() when checking files, as file_exists() returns true on directories. In addition, you might want to see if getimagesize() returns FALSE to make sure you have an image.

[Solved] CodeIgniter File_exists Not Working, file_exists() does NOT search the php include_path for your file, so don't use it before This is at least the case on this Windows system running php 5.2.5 and � CodeIgniter uses a front controller so paths are always relative to the main site index. If your server is running an open_basedir restriction this function might not work if you are trying to access a file above the calling script. write_file (' path ', $data) Writes data to the file specified in the path.

Use like this.

$g = base_url().'upload/image.jpg';
if(file_exists($g) !== null){//your code..}

This is works for me in CI.

file_exists - Manual, <?php if (file_exists("snapshot1.png")) { print "Snapshot1.png exists!\n"; } else { print "Snapshot1.png does not exist!\n"; } ?> Author's Note: The result of file_exists() is cached, which means you first need to call the files with flock(), Permissions, Setting permissions, Changing file ownership, Working with directories� If your server is running an open_basedir restriction this function might not work if you are trying to access a file above the calling script. write_file ($path, $data [, $mode = 'wb']) Writes data to the file specified in the path. If the file does not exist then the function will create it.

Checking whether a file exists: file_exists() – Hacking with PHP , Get code examples like "codeigniter check view file exists" instantly right from your google search public function view($view, $vars = array(), $return = FALSE). 4 $file_exists && ! file_exists($_ci_path)) bootstrap carousel foreach loop not working wordpressp php wp � bootswatch import theme into� PHP unlink not working in codeigniter +3 votes. asked Nov 9, Unlink does not work like that, its works on relative path, try it like this : file_exists

codeigniter check view file exists Code Example, file_exists not working in codeigniter I am working with codeigniter v3. of “ true” to check that the file exists and throw FileNotFoundException() if it does not. In this article, i will show you how to check file is exists or not in folder laravel 6 application. we can easily check file is exists or not in directory using File or Storage facade in laravel 6 project. i will give you simple and more solution of laravel 6 check file is available or not from public folder or storage folder.

How to check if view file exist in codeigniter?, We can use file_exists() to check whether a file exists or not, but keep in mind that this does not work properly with HTTP URLs. This function� file_exists() needed 2.8 and 2.9 seconds, respectively. The absolute numbers are off course system-dependant, but it clearly indicates that file_exists() is faster. up

  • Maybe site_url() returns something like If you want to use file_exists(), you have to provide a path to the filesystem where your code is running. Try replacing that line to be like this: $image_path_medium = $_SERVER['DOCUMENT_ROOT'].'/assets/images-products/medium';.
  • Looking at confirms what I've stated above.
  • done changes as per your suggestion.. but now also its avoiding if condition
  • Did you tried with a file that you are 100% that doesn't exist?
  • Can you, in a different file, do something like this: readfile('[path that was echoed on the other code]');?
  • it showing /home/servername/public_html/‌​e.jpg
  • thanks, but it also didnt worked it always avoids if condition even if the image is available..
  • what does $image_file_path and $image_name_with_path prints
  • you said it was showing /home/servername/public_html/‌​‌​e.jpg now you saying file exists not working. echo $image_file_path and $image_name_with_path before if condition. and what you got.just write the full not write whats going on
  • Thanks it worked, but / was missing in line $image_file_path=FCPATH.'assets/images-products/medium'. $home_technology[$key]->product_sku . "-" . "a" . "-medium.jpg"; before $home_technology[$key]->product_sku
  • Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.