Upload image via PHP

Good Day, Im using php sdk.

May I know how can I upload an image in backendless files directory?

For example I want to upload an image namely pic.jpg.
Then i want to upload it in /media/logos/ directory.
Also i want to rename the pic.jpg into <userid>.jpg during upload. so it will be /media/logos/<userid>.jpg

Note: I already have how to get <userid>

HTML:
<input type="file" name="logo" accept="image/*" />

Hi Pluto,

Please read the documentation:
https://backendless.com/documentation/files/php/files_file_upload.htm

Regards,
Mark

I tried to read this one and I come up with this:

$file = new File();
$file->setPath($_FILES[‘logo’][‘tmp_name’]);
$saved_file = Backendless::$Files->upload( $file , ‘media/logo’ );

it was uploaded in the directory. but the problem is, it was saved as php<some random id>.tmp

its suppose to be pic.jpg right?

I tried to read this one and I come up with this:

$file = new File();
$file->setPath($_FILES[‘logo’][‘tmp_name’]);
$saved_file = Backendless::$Files->upload( $file , ‘media/logo’ );

it was uploaded in the directory. but the problem is, it was saved as php<some random id>.tmp

its suppose to be pic.jpg right?

Hi Pluto,

We made a few changes in the SDK to accommodate this use-case. Please make sure to get the latest copy of the SDK and make sure to call the following method in the code:

$file->setFileName( $_FILES['logo']['name'] );

Regards,
Mark

Thanks Mark. I will try this one later. All the best!