# Upload files not working

**URL:** <https://discourse.slimframework.com/t/upload-files-not-working/1473>\
**Category:** Questions\
**Created:** [May 6, 2017, 12:36pm UTC](https://discourse.slimframework.com/t/upload-files-not-working/1473 "2017-05-06T12:36:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemantoswal](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hemantoswal](https://discourse.slimframework.com/u/hemantoswal)\
**Post date:** [May 6, 2017, 12:36pm UTC](https://discourse.slimframework.com/t/upload-files-not-working/1473/1 "2017-05-06T12:36:32Z")

</div>

Hello,  
I am using webix as frontend framework and slim as backend framework.  
I am using webix.uploader to send image files.  
When i send files from my frontend -  
it shows in network tab under request Payload as  
------WebKitFormBoundary0axGlH6qUYclDYmG  
Content-Disposition: form-data; name=“upload”; filename="20160208\_132145.jpg"  
Content-Type: image/jpeg

------WebKitFormBoundary0axGlH6qUYclDYmG–

but in my php i am using following code to retrieve uploaded files  
$files = $request-\>getUploadedFiles();

but the $files variable returns empty array.

---

<div class="post-metadata">

**Author:** ![svanbelleghem](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/svanbelleghem/32/405_2.png) [@svanbelleghem](https://discourse.slimframework.com/u/svanbelleghem)\
**Post date:** [May 23, 2017, 2:17pm UTC](https://discourse.slimframework.com/t/upload-files-not-working/1473/2 "2017-05-23T14:17:31Z")

</div>

Had the same issue. Fixed it by using $\_FILES instead.

```
$app->post('/', function ($request, $response, $args) {
        $mapper = new DatabaseMapper($this->db);
        return $mapper->updateDatabase($_FILES);
    });
```

---

<div class="post-metadata">

**Author:** ![hemantoswal](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hemantoswal](https://discourse.slimframework.com/u/hemantoswal)\
**Post date:** [May 23, 2017, 6:05pm UTC](https://discourse.slimframework.com/t/upload-files-not-working/1473/3 "2017-05-23T18:05:20Z")

</div>

I did not understand logic behind the code.  
I am using uploadPhoto function.  
Means should I use app-\>post( ‘uploadPhoto’, function (…))  
And I am getting error near databaseMapper.  
Can you give example in detail.  
Thanks

---

<div class="post-metadata">

**Author:** ![svanbelleghem](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/svanbelleghem/32/405_2.png) [@svanbelleghem](https://discourse.slimframework.com/u/svanbelleghem)\
**Post date:** [May 24, 2017, 6:39am UTC](https://discourse.slimframework.com/t/upload-files-not-working/1473/4 "2017-05-24T06:39:15Z")

</div>

I’m very sorry. The example I gave is one from a project of my own.

Can u try to change  
`$files = $request->getUploadedFiles();` to `$files = $_FILES;`

$\_FILES is an associative array of items uploaded to the current script via the HTTP POST method.

Then you should be able to get the file and filename by using this:  
$inputFile = $files[‘file’][‘tmp\_name’];  
$inputFileName = $files[‘file’][‘name’];

But to make sure, print the content of `$_FILES` to see what it contains.

---

<div class="post-metadata">

**Author:** ![hemantoswal](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hemantoswal](https://discourse.slimframework.com/u/hemantoswal)\
**Post date:** [May 24, 2017, 8:34am UTC](https://discourse.slimframework.com/t/upload-files-not-working/1473/5 "2017-05-24T08:34:37Z")

</div>

I used following code to get uploaded file.  
In index.php I declared  
$app-\>post (‘UploadPhoto’, ‘UploadPhoto’);  
Then  
I declared the function as  
function UploadPhoto ( $request , $response ) { $files = $\_FILES; /\* here code for file manipulation \*/} In this function $files variable remains blank array.

But still I am not getting reference to uploaded file.

---

<div class="post-metadata">

**Author:** ![svanbelleghem](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/svanbelleghem/32/405_2.png) [@svanbelleghem](https://discourse.slimframework.com/u/svanbelleghem)\
**Post date:** [May 24, 2017, 11:09am UTC](https://discourse.slimframework.com/t/upload-files-not-working/1473/6 "2017-05-24T11:09:59Z")

</div>

Then I’m guessing that the problem lies elsewhere. Perhaps in the way u sending the file to the endpoint.

---

<div class="post-metadata">

**Author:** ![hemantoswal](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@hemantoswal](https://discourse.slimframework.com/u/hemantoswal)\
**Post date:** [May 31, 2017, 2:01am UTC](https://discourse.slimframework.com/t/upload-files-not-working/1473/7 "2017-05-31T02:01:49Z")

</div>

Hello,Thank you very much for your help.I will try different options.Thank you
