0

I have a method that successfully uploads local files to an S3 bucket using the amazon SDK, all I need is a valid local path/to/file, which is the second param below:

$this->saveToAmazon($pathOnS3,$filename);

These local files are uploaded by the user and handled using the $_FILES global. Once the user uploads, we are copying to a local uploads folder via move_uploaded_file(). From there, we are calling the above function. This works fine, although this got me thinking.

Since for the life of the request, the file can be accessed temporarily via $_FILES['file']['tmp_name'], is it possible to 'hack' together a temporary valid file path to provide the saveToAmazon() function without having to call move_uploaded_file() and using the local uploads folder? essentially tapping in to the local php/tmp directly?

AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231
  • You _should_ be fine skipping `move_uploaded_file` these days. See https://stackoverflow.com/questions/16276835/php-move-uploaded-file-why-is-it-important – miken32 Dec 18 '18 at 22:55
  • @miken32 thanks for the reply, I saw that link - saying I 'should be fine' is not very helpful. What is the solution you're proposing instead of using `move_file_upload`? I appreciate any suggestions - p.s. `rename()` didn't work for me, the tmp file and renamed file are oth gone following the `rename()` function call. – AnchovyLegend Dec 18 '18 at 23:51
  • What's wrong with `$this->saveToAmazon($pathOnS3,$_FILES["file"]["tmp_name"]);`? – miken32 Dec 18 '18 at 23:52
  • Tried it, simply doesn't work, the temp file isn't a valid / readable file --- try this: upload a picture and try to construct a valid path using `$_FILES["file"]["tmp_name"]` or even just try to call `file_get_contents` on it - doesn't work. – AnchovyLegend Dec 18 '18 at 23:54

0 Answers0