Welcome Guest, Not a member yet? Register   Sign In
PHP file_exists() function not working Codeigniter 3.1.9
#4

Ah, think I see what's going on in here.

You are trying to use same path from both local and remote / web-server context.

When it's your PHP trying to access files, it's local file reference in your harddrive, but when browser tries to request a file, it'll need to add domain name, which is pointed to a web server, and web server knows which local files and folders on hard drive would be linked to said domain.

So file_exists needs local path, and img src needs remote path.

If your index.php is on same level than assets directory, this should work:
PHP Code:
$file_path 'assets/img/user_img/'.$user_id.'.jpg';
if (
file_exists($file_path)) {
 
   $data['user_img'] = '<img src="'.base_url($file_path).'">';
} else {
 
   $data['user_img'] = '<img alt="No Image" src="https://dummyimage.com/100x100/000/fff">';

Reply


Messages In This Thread
RE: PHP file_exists() function not working Codeigniter 3.1.9 - by Pertti - 07-18-2018, 11:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB