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

boboboy's avatar

Getting the real path of the uploaded file without saving to the project directory

How to get real path of uploaded file without saving file. When uploading a file and trying to get the real path, it always shows the real path of the uploaded file but with the .tmp extension. is it possible to get the actual file path without saving?

0 likes
13 replies
Sinnbeck's avatar

What do you mean by the real path? Do you mean the original file name ? ->getClientOriginalName()

Sinnbeck's avatar

@luqmansolihin So the name? Or do you mean the path on the computer it was uploaded from (that isnt possible) ?

boboboy's avatar

@Sinnbeck For example I am upload file from C:\Users\anonym\Downloads\img.jpg. how to get this path?

Sinnbeck's avatar

@luqmansolihin Not possible. Your browser does not allow the local path to be shown. The only thing you can get is the img.jpg part

boboboy's avatar

@Sinnbeck then if I will continue the file to the Rest API, should it be saved to storage first?

Sinnbeck's avatar

@luqmansolihin Do you need a backup of it? If not, you can probably just send the contents of the file directly.

boboboy's avatar

@Sinnbeck I try to upload with $request->file('img')->getRealPath() it always fails because RestAPI asks for file with extension .jpg not .tmp

boboboy's avatar

@Sinnbeck this is my code

    $params = $request->validate([
        'name' => 'required',
        'description' => 'required',
        'is_active' => 'required',
        'start_date' => 'required',
        'end_date' => 'required'
    ]);

    $response = Http::withToken($token)
        ->attach('img', $request->file('img')->getContent())
        ->post(config('api.host').'banner-promo', $params)
        ->object();

but always failed.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@luqmansolihin Seems you are missing an argument

$response = Http::withToken($token)
        ->attach('img', $request->file('img')->getContent(), $request->file('img')->getClientOriginalName())
        ->post(config('api.host').'banner-promo', $params)
        ->object();

Please or to participate in this conversation.