How to call UploadHandler.php with PHP - blueimp jQuery File Upload

Christine Wilson picture Christine Wilson · May 14, 2013 · Viewed 15.3k times · Source

Does anyone know how to upload images using PHP and calling the UploadHandler.php?

I'm not sure what information needs to be passed and in what format.

Here's what I have so far:

$prop="test";
session_id($prop);
@session_start();
$url = 'http://christinewilson.ca/wp-content/uploads/2013/02/port_rhdefence.png';
$file_name[] = file_get_contents($url);

error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler(array(
    'user_dirs' => true
));

Answer

user1587439 picture user1587439 · Jan 23, 2015

The response is contained within the UploadHandler class object and can be retrieved like shown below.

$upload_handler = new UploadHandler();
$response = $upload_handler->response;
$files = $response['files'];
$file_count = count($files);
for ($c = 0; $c < $file_count; $c++) {
   if (isset($files[$c]->error))
       continue;
   $type = $files[$c]->type;
   $name = $files[$c]->name;
   $url = $files[$c]->url;
}