PHP fopen(): Filename cannot be empty cause by getRealPath return false

  • | 1171 points

    I'm developing Laravel project on Windows 10 locally using Laragon

    PHP version: 7.1.8 64bit NTS

    related php.ini that I know is

    post_max_size = 8M

    file_uploads = On

    source code

    // if no image uploaded
    if (!$request->hasFile('profile_picture')) 
    throw new \Exception("No image found");
    // get uploaded image
    $image = $request->file('profile_picture');
    // store to storage/app/users/
    Storage::putFileAs('users', $image ,auth()->id());

    UploadedFile Instance proved that image was uploaded successfully, but the realpath is false
    this bug(?) cause Laravel cant read the file, so threw the error
    here is the function cause error

    In my opinion, this is server configuration issue, probably problem on php.ini,

    but I'm not familiar with server configuration, and there is not too much topics online related with this issue.

    I know the problem caused, but I don't know how to solve it.

    Please give me a hand, appreciate your help.

  • administrators
    | 131258 points

    @LostNCG : I'll check and get back to you later.

  • administrators
    | 131258 points

    I see no problem with your PHP settings as the file is uploaded to Temp folder. How about creating folder users in storage/app?

  • | 1171 points

    @leokhoa tried, not this reason

  • | 1171 points

    Feels good to solve a problem myself

    After 2 days, I finally figure out why, last time I use the PHP Thread Safe version to develop this application and it work normally.

    By now, I'm using Not Thread Safe version, after testing, I confirm that this issue are caused by different file info result of NTS & TS

    For PHP 7.1.7 64bit TS

    For PHP 7.1.8 64bit NTS

    So by now we can know that bug occurs on temp folder setting,

    For NTS version, temp folder on C:\Windows\Temp,

    No permission of this folder cause PHP can't read the realPath (I guess), realPath return false

    For TS version, temp folder on C:\Users\YQuan\AppData\Local\Temp,

    Allow to access, realPath readable


    1. Change permission to folder effected

    I won't using this method because too messy to change permission on Windows system

    1. set upload_tmp_dir in php.ini to "C:\Users{username}\AppData\Local\Temp", then restart server

      this method is easier.

  • administrators
    | 131258 points

    @LostNCG : Nice catch!
    I wonder why on earth the C:\Windows\Temp folder needs permission to write on ..
    And TS & NTS version of PHP use different tmp folders!!!

    Your issue is very hard to find and fix but at last you could make it.

Log in to reply

Looks like your connection to Laragon was lost, please wait while we try to reconnect.