Upload files not working


#1

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.


#2

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);
    });

#3

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


#4

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.


#5

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.


#6

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


#7

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