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?
What do you mean by the real path? Do you mean the original file name ? ->getClientOriginalName()
@luqmansolihin So the name? Or do you mean the path on the computer it was uploaded from (that isnt possible) ?
@Sinnbeck For example I am upload file from C:\Users\anonym\Downloads\img.jpg. how to get this path?
@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
@Sinnbeck then if I will continue the file to the Rest API, should it be saved to storage first?
@luqmansolihin Do you need a backup of it? If not, you can probably just send the contents of the file directly.
@Sinnbeck I try to upload with $request->file('img')->getRealPath() it always fails because RestAPI asks for file with extension .jpg not .tmp
@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.
@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 sign in or create an account to participate in this conversation.