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

assuming you upload the images in the upload folder, you should have a route like:
```$routes->match(['get', 'post'], 'imageRender/(Confusedegment)', 'RenderImage::index/$1');```
and then a class to return the image. it should have something that verifies if user is logged or some kind of verification to prevent averybody from seeing the image (otherwisee defeats the purpose of all this and you would be better just putting the images in the public folder). something like this:
```
<?php

namespace App\Controllers;

use CodeIgniter\Controller;

class RenderImage extends Controller
{
public function index($imageName)
{
if(($image = file_get_contents(WRITEPATH.'uploads/'.$imageName)) === FALSE)
show_404();

// choose the right mime type
$mimeType = 'image/jpg';

$this->response
->setStatusCode(200)
->setContentType($mimeType)
->setBody($image)
->send();

}

}
```

and in the view the image would be something like this:
```<img src="/imageRender/restaurant_imgs/<?= i$mage_name ?>" alt="image">```
Reply


Messages In This Thread
RE: How to access images under writable folder - by ale_vh - 11-05-2020, 04:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB