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
));
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;
}
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With