1
$data = base64_decode($_POST['data']);

if (!is_dir(UPLOAD_PATH)) {
    return 'Error: Upload path does not exist';
}

if (!file_put_contents(UPLOAD_PATH.$name, $data)) {

    return 'Error while writing data, please check your server config';

}else return true;

When i upload photo using above code then it Looses Mime-type (content-type) header response. You can see i've used function like this.

Rajesh
  • 181
  • 1
  • 11

1 Answers1

1

You can configure mimetype for file_put_contents using a stream context as follow the documentation:

int file_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] ) http://php.net/manual/en/function.file-put-contents.php

http://php.net/manual/en/function.stream-context-create.php

Gabriel Pereira
  • 160
  • 1
  • 10