It seems that I have looked everywhere and tried everything and I can not get this to work, any help would be much appreciated! I am using Blueimp's jQuery File Upload. I have changed the UploadHandler.php in the following ways to make this upload work with multiple records and places within my system. I am using PHP and MySQL.
Added to handle_file_upload function so that the file path, file name, file type, file size, the record type, and the "job number" is uploaded to a table I created in MySQL for each different file.
$file->upload_to_db = $this->add_file($job_num, $recordtype, $file_path, $filename, $type, $file_size);
This job number is sent to the page (with the file upload) as a get variable as well as a hidden form field to send to the Handler when adding a file. The add_file function I added is as follows:
function add_file($job_num, $recordtype, $filepath, $filename, $filetype, $filesize)
{
$filepath = addslashes($filepath);
$insert_query = $this->query("INSERT INTO fileupload (job_num, recordtype, file_path, file_name, file_type, file_size) VALUES ('".$job_num."','".$recordtype."','".$filepath."','".$filename."','".$filetype."','".$filesize."')");
return $insert_query;
}
The query function:
protected function query($query) {
$database = $this->options['database'];
$host = $this->options['host'];
$username = $this->options['username'];
$password = $this->options['password'];
$Link = mysql_connect($host, $username, $password);
if (!$Link){
die( mysql_error() );
}
$db_selected = mysql_select_db($database);
if (!$db_selected){
die( mysql_error() );
}
$result = mysql_query($query);
mysql_close($Link);
return $result;
}
I have a function for the delete as well. Now, this all works fine. Every file I add is saved and the path is stored in the database. From here I had to find a way to only show the files uploaded for that record instead of showing all files for every record. I modified the get function:
public function get($print_response = true) {
if ($print_response && isset($_GET['download'])) {
return $this->download();
}
$uploads = $this->query_db();
return $this->generate_response($uploads, $print_response);
}
The query_db function:
public function query_db() {
$uploads_array = array();
// error_log("Job Num: ".$this->job_num."\n\n",3,"error_log.txt");
$select_result = $this->query("SELECT * FROM fileupload WHERE job_num=423424");
while($query_results = mysql_fetch_object($select_result))
{
$file = new stdClass();
$file->id = $query_results->id;
$file->name = $query_results->file_name;
$file->size = $query_results->file_size;
$file->type = $query_results->file_type;
$file->url = "filepath_to_url/".$query_results->file_name;
$file->thumbnail_url = "filepath_to_thumbnail/".$query_results->file_name;
$file->delete_url = "";
$file->delete_type = "DELETE";
array_push($uploads_array,$file);
}
return $uploads_array;
}
Where the filepath is correct on my system. This, again, works just fine. But as you can see from the query in the query_db function I have the job_num hard coded. I need a way to get this when the first page is loaded. I have looked for a way to do this and nothing has worked. When I submit/add other files I can use the $_REQUEST['job_num'] to get it, but not when the page is loaded. I am not very familiar with OOP PHP so some of this is new to me.