I'm trying to get this to instead of uploading files in a nice way and placing them on the server, to talk instead to some php that will (hopefully) place them into a MySQL database. I can get it posting just fine, but instead of returning anything useful - or succeeding - I get:
Error SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
I do not know why. Firebug tells me it talks to the php just fine. I'm unsure how to extract the files which are posted under the name of "files[]" in php, to identify and handle them separately. I've not found any clear to understand method of extracting a posted array (I presume this is what it is?). Would this be causing the JSON.parse error, through not handling the end method well? Or is there something else going on before that?
New to AJAX, and now frustrated. Help appreciated.
Originating form looks like this
Which pastes to this php (currently does not a lot, yet)
The way you get jQueryFileUploader to do what you want is to subclass the class that does all the work on the server.
If you look at the file structure on the server where you installed the FileUploader it looks something like this
what gets run by default is the index.php in the php
folder, and that instantiates the UploadHandler class like so
?php
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler();
And it is the code in that class that does all the actual work of putting files on disk etc etc...
Now to make it do what you want it to rather than its default process, you need to code your own functionality either instead of the default or as well as the default functionality.
So what you need to do is subclass the default class and override whichever method in the real class does the work you want to alter.
To change the process of uploading a file, you would add this method to your MyUploadHandler class
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
class MyUploadHandler extends UploadHandler
{
/*
* Maintain our database:
* For each uploaded file, add an entry to the tbl_xxx
*/
protected function handle_file_upload($uploaded_file, $name, $size,
$type, $error, $index = null,
$content_range = null)
{
// this does what woudl have automatically been done
// before we subclasses anything
$file = parent::handle_file_upload($uploaded_file, $name, $size,
$type, $error, $index,
$content_range);
/* Now we add some extra processing
if the file uploaded with no problems
*/
if ( empty($file->error) ) {
$sql = "INSERT INTO tbl_xxx ( a,b, imgpath)
VALUES('x', 'y', '$file->name' )";
$db->query($sql);
}
return $file;
}
} // end of class
$upload_handler = new MyUploadHandler($site_params);