file exists is failing |
I am working my way through a new library call image crud, with the debugger. I see that this line 1 is failing:
$ext = pathinfo($view, PATHINFO_EXTENSION); $file = ($ext == '') ? $view.'.php' : $view; $view_file = 'assets/image_crud/views/'; if (file_exists($view_file.$file)) <<<line 1 { $path = $view_file.$file; $file_exists = TRUE; } if ( ! $file_exists) { throw new Exception('Unable to load the requested file: '.$file, 16); } Looking in the debugger I see that $view_file="assets/image_crud/views/". I also see $file="list.php". I am not familiar with this syntax string.string . I can see the file path exists on the hard drive but have no idea why this would fail. I wonder if I am looking at the correct "assets" dir on the hard drive? The file I can see on the drive is /app/assets/image_crud/views/list.php. But notice that $view_file doesn't start with a "/". I also tried hard coding the path if (file_exists('assets/image_crud/views/list.php')) and this also fails. BTW, I am using Ubuntu and php 5.6. My code is in a Docker container. I also tried the full path of : if (file_exists('/opt/docker-substantiator/app/assets/image_crud/views/list.php')) and this also fails. What am I missing here?
proof that an old dog can learn new tricks
(04-15-2020, 08:40 AM)richb201 Wrote: I am working my way through a new library call image crud, with the debugger. I see that this line 1 is failing: Well this seems like a problem that many other php programmers have seen! Obviously, no one else up here. Here is a link where users recommend a few other ways to check if a file exists. https://stackoverflow.com/questions/4253...sts-in-php I will try these today. But I have one question. They seem to all show using a full url. My file is local. The examples show the use of http://localhost/ etc. I am trying to use a local path. I am concerned about this. Secondly, I am using Docker. I can access my code directory from my code with the debugger. I am just not sure if my problem is related to Docker and the way I can reach places on the hard drive that are NOT in the container! Any Docker-heads out there in CI world?
proof that an old dog can learn new tricks
Excellent idea. When I do this my cwd is /app. So I changed the code to if (file_exists("/assets/image_crud/views/list.php")), thinking that would check /app/assets/image_crud/views/list.php. That fails too! I saw a few recommendations on stackoverflow such as using getimagesize() or get_headers(). Both of these seem to use the full path http://localhost/etc, which really won't work for me when I am on my actual AWS server.
How about if I use the filesystem helper? I am using CI 3, btw. I tried using $this->load->helper('filesystem'); and got: Unable to load the requested file: helpers/filesystem_helper.php I noticed that the _$SERVER[USER] is "daemon". But when I go to permissions for list.php, daemon is not one of the users I have a choice of giving access to. I am using ubuntu. Could this be the issue, and if so how do i add daemon to permissions?
proof that an old dog can learn new tricks
I have pretty much narrowed the problem down to Docker and the way in which the CI application directory is loaded. I haven't figured out how to fix it yet. I order a book on Docker today from Amazon to see if I can figure out how to bind mount. Seems that this can only be done in the Dockerfile and I don't know where it is located. I just hope that the guy who configured Docker for me did this on my machine, not his.
proof that an old dog can learn new tricks
|
Welcome Guest, Not a member yet? Register Sign In |