I have a form which lets the user upload the image file.
<div id="imageDiv">
Image Path : <input class="imageOption" type="file" id= "uploadImageFile" name="uploadImageFile" >
</div>
The problem comes when I try to fetch the path from temp folder. I won't be needing the image files after processing the request. When I try to fetch the path with something like this
$imagePath = $_FILES['uploadImageFile']['tmp_name'];
The path looks like C:\wamp\tmp\phpA123.tmp. The API I'm using would require a path with extension of an uploaded image like this C:\wamp\tmp\image.png
Couldn't figure out a way to do so unless I want to copy this image to some other upload folder and use it. I don't want these images logged in a server
Thanks
It would be helpful to know the specific API in use, but no well written file storage API should ever have to rely on the uploaded file name being used to store a file. You should be able to use the temp file contents in the API, and specify the file name separately.
In L5:
// Get the UploadedFile object
$file = Request::file('uploadImageFile');
// You can store this but should validate it to avoid conflicts
$original_name = $file->getClientOriginalName();
// This would be used for the payload
$file_path = $file->getPathName();
// Example S3 API upload
$s3client->putObject([
'Key' => $original_name, // This will overwrite any other files with same name
'SourceFile' => $file_path,
'Bucket' => 'bucket_name'
]);
If you want to get same output as -
$imagePath = $_FILES['uploadImageFile']['tmp_name'];
in Laravel, you can do something like this as described by @cdbconcepts -
$file = Request::file('uploadImageFile');
$imagePath = $file->getPathName()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With