Welcome Guest, Not a member yet? Register   Sign In
How to access images under writable folder
#10

(This post was last modified: 03-30-2022, 08:24 AM by dgvirtual.)

(08-04-2020, 12:09 PM)jreklund Wrote: You need to upload them to /public/uploads or make a PHP-reader that reads the image from writable/uploads and outputs it to the user, with a correct mime type.

To resurrect a theme: I need to make some uploaded files available only to logged-in users.

I guess one way to do that would be to put the upload files into a public directory while rewriting their names into some md5 string, like nice-picture_a03384874133c262676aab57fecb8ced.jpg , so that without a link pointing to it there would be no easy way to get the image.

But I see you also suggest to "make a PHP-reader" - could someone point me in the right direction on how that is to be done? What would be the-codeigniter-way of allowing access to files outside public directory?

I have found this code example online, is it the way to go? I imagine it would go into some controller that would be provided as src link with the name of the file I want to provide as first argument (segment) after the controller name in an html page...

PHP Code:
$file '/absolute/path/to/file.ext';

if (
file_exists($file)) {
    
header('Content-Description: File Transfer');
    
header('Content-Type: application/octet-stream');
    
header('Content-Disposition: attachment; filename='.basename($file));
    
header('Content-Transfer-Encoding: binary');
    
header('Expires: 0');
    
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    
header('Pragma: public');
    
header('Content-Length: ' filesize($file));
    
ob_clean();
    
flush();
    
readfile($file);
    exit;

==

Donatas G.
Reply


Messages In This Thread
RE: How to access images under writable folder - by dgvirtual - 03-30-2022, 08:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB