Image writable file doesn't appear in the view CodeIgniter4

85 Views Asked by At

Ok so i am working on a project with WAMP & CodeIgniter4.

I am working actually on a form that submit pictures/videos. I save those files on the server & in the database (i save the local path and the web path) in the controller. then in the view i try to display them. (sorry for my english)

Here is a part of the function in my controller that manages the form :

    $mediaFiles = $this->request->getFiles('mediaFile[]');

                foreach ($mediaFiles as $tabFiles) {
                    
                    foreach ($tabFiles as $file) {

                        if ($file->isValid() && !$file->hasMoved()) {

                            $newName = $file->getRandomName();

                            $file->move(WRITEPATH . 'uploads/', $newName);

                            $cheminWeb = base_url('writable/uploads/' . $newName);

                            $cheminLocal = WRITEPATH . 'uploads/' . $newName;

                            $data = [
                                'idNews'            => $actualiteId,
                                'nameMedia'         => $file->getName(),
                                'typeMedia'         => $file->getClientMimeType(),
                                'webPathMedia'      => $cheminWeb,
                                'localPathMedia'    => $cheminLocal,
                                'isFront'           => 0,
                                'dateCreationMedia' => date('Y-m-d H:i:s') 
                            ];

                            $this->mediasModel->insert($data);

                        }

                    }

                }

And the part in the view related to it

<?php if (isset($tabMedias) && !empty($tabMedias)) { ?>
                <?php foreach ($tabMedias as $media) { ?>
                  <div class="col-md-4">
                    <div class="service-item">
                      <a href="#" class="services-item-image"><img src="<?php echo $media['webPathMedia']; ?>" class="img-fluid" alt="Test"></a>

The result of this is : i don't see the images but i see the alt "Test" instead.

The insertion in the database is good.

The file exists in the folder.

The path that i try to work with looks like : http://projectname/writable/uploads/randomname.jpg

I work with a VirtualHost. His path is : C://www/projectname/public.

In My App.php in /Config,public string $baseURL = 'http://projectname/';

I really don't know what to do. I need some help please.

Thanks for the any answers/advices.

I tested with and without /writable in the path, did not wanted to htaccess file since i don't really know how it works clearly (in case of problems with rights with the writable file).

I also tried to get the source code of the page and try to open the file in a new tab it does not works ,it is considered as a controller name (i have not the problem with images outside the writable, for example, if the file is in nameproject/public/assets/images/nameimage)

0

There are 0 best solutions below