Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nmihaylov's avatar

Laravel Valet and file uploads

Hi guys,

I'm using Laravel Valet from a month now and I have faced a strange problem - an old project with file uploads based Laravel 5.2 is not uploading files at all. When I was using Vagrant with Homestead this functionality was okay and also on the production server (a Digital Ocean + Forge) all is working fine. But today I have noticed that the file uploads are not working. Do anyone have faced similar issue? I'm thinking this maybe connected to the file permissions but I'm not actually sure how can I test it.

PS. the project is not mine and I'm doing only some bugfixes for the client

0 likes
6 replies
Nakov's avatar

Can you share what errors are you getting? I haven't had an issue and I am using only Valet.

Did you tried different browser? In case the popup for selecting a file does not show? Check your developer tools and in the Network tab should give you some better understanding on what is going on. Check storage/logs/*.log file for any errors.

More info better help :)

nmihaylov's avatar

Thank you, Nakov!

So far I've found that native Laravel Valet driver does not support .php files in public folder and strangely this is what this project is using (no idea why :D). I'm now trying to figure out how to run .php files in public folder and after that will see it if will work.

Thank you also for the tips on the network tab - this is where I've found that the .php file in public folder is not executed.

Nakov's avatar

@nmihaylov That does not make sense :)

Each laravel project has a public folder and the index.php file is what boots the whole application. So you have a different issue, maybe permissions or something, but other than that, I completely disagree with what you said above.

nmihaylov's avatar

@Nakov sorry, maybe my explanation was not clear enough. Here is what I mean - if you add another ****.php file into the public folder of the project like phpinfo.php it will not be executed if you are using the default Laravel Valet driver.

In my case into the public folder I have a subfolder called "uploads" where another index.php file is presented and the uploading logic is added into this file. This is why I said that ***.php files are not supported but missed to clarify my case.

Below I'm pasting what I have added as custom LocalValerDriver in the project folder in order to execute the other .php files into the public folder:

<?php

class LocalValetDriver extends LaravelValetDriver
{

    private $site_folder = '/public';
    /**
     * Determine if the driver serves the request.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return void
     */
    public function serves($sitePath, $siteName, $uri)
    {
        return true;
    }

    /**
     * Determine if the incoming request is for a static file.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return string|false
     */
    public function isStaticFile($sitePath, $siteName, $uri)
    {
        if (file_exists($staticFilePath = $sitePath.$this->site_folder.$uri)) {
            return $staticFilePath;
        }

        return false;
    }

    /**
     * Get the fully resolved path to the application's front controller.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return string
     */
    public function frontControllerPath($sitePath, $siteName, $uri)
    {
        $path = $sitePath.$this->site_folder;

        return strpos($uri, '.php')
            ? $path.$uri
            : $sitePath.'/public/index.php';
    }
}    

Credits for the above code are for the guy from this post: https://github.com/laravel/valet/issues/424#issuecomment-375432585

Nakov's avatar

@nmihaylov okay, that makes sense, but that's really reasonable, because now what you've done is you've exposed every php file in your project to the public :) so everyone can go and see your code.

nmihaylov's avatar

@Nakov This is only for my local env (my laptop) and not for production server so we are safe here. The real reason behind the other ****.php files into public folder is still something I need to understand why it is done this way and how it is working because it still does not upload files.

Please or to participate in this conversation.