Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
));
like image 840
Christine Wilson Avatar asked Dec 27 '22 03:12

Christine Wilson


2 Answers

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;
}
like image 160
user1587439 Avatar answered Mar 22 '23 22:03

user1587439


I could not find a way to get the file name via php so I had to do it myself.

First you need to add a public variable under UploadHandler.php

class UploadHandler
{
    public $file_name;
    protected $options;

and then add that to the function that creates the name

protected function get_file_name($name,
        $type = null, $index = null, $content_range = null) {

    $this->file_name = $this->get_unique_filename(
        $this->trim_file_name($name, $type, $index, $content_range),
        $type,
        $index,
        $content_range
    );
    return $this->file_name;
}

then under index.php you could do something like this

$upload_handler = new UploadHandler();
echo "\r\n [" . $upload_handler->fileName . "]\r\n";

I hope this help you or save someone some time :)

like image 31
Kal Avatar answered Mar 23 '23 00:03

Kal