Getting path/URL of uploaded files |
Hey guys, I hope you're doing alright in this pandemic.
I've searched the forums and StackOverflow but I can't seem to find solutions to what I believe is a very simple concept: is there a method that returns the full path/URL of the uploaded file? Here's what my flow looks like: 1. Image is uploaded via a form. 2. Image is moved using '$file->store()' 3. The value returned is inserted into the database (e.g. "20200626/1593171870_2ebce4905386e30800cf.jpeg") I'm unable to build a path/URL that can display the image in another controller. I've tried 'realpath()' in combination with 'APPPATH', 'WRITEPATH', and the value attained in step 3 but I'm given 404 errors. An example: Code: http://localhost:8080/Users/path/to/app/writable/uploads/20200626/1593171870_2ebce4905386e30800cf.jpeg So, how does one point to the path/URL of an uploaded file in CI? Thanks for taking time to read this.
In view you will call this code after image uploaded successfully.
echo $image_data['full_path'];
(06-26-2020, 06:34 PM)dariusbaker Wrote: Seems like you already know the answer but you cannot access assets in /app/writable/uploads using HTTP because that folder is outside the webroot. If you want to display the image using some HTML tag then you will have to move (or copy) the image into the webroot somewhere, i.e. /public/assets/images/20200626/somefile.jpg. The absolute path to the file would be PHP Code: $imagePath = WRITEPATH . 'uploads/' . $imageLocation; Assumes $imageLocation comes from the database and includes the date folder and the file's full name. |
Welcome Guest, Not a member yet? Register Sign In |