我已按照此链接中使用 DB 的说明进行操作:https ://github.com/blueimp/jQuery-File-Upload/wiki/Working-with-databases 。我检查了一切,尤其是连接设置。他们是正确的。但它一直显示“错误{}”。我试图在我的服务器的日志文件和调试工具上找到线索,但没有运气。
这是截图:
索引.php
error_reporting(E_ALL | E_STRICT);
$sid=$_GET['sid'];
$caption=$_GET['title'];
$view="0";
require('UploadHandler.php');
$upload_handler = new UploadHandler();
此外,我还附上了“UploadHandler.php”,看看是否有任何隐藏的错误。
<?php
function __construct($options = null, $initialize = true, $error_messages = null) {
$this->options = array(
// mysql connection settings
'database' => '****',
'host' => 'localhost',
'username' => '****',
'password' => '****',
// end
'script_url' => $this->get_full_url().'/',
'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/',
'upload_url' => $this->get_full_url().'/files/',
'user_dirs' => false,
'mkdir_mode' => 0755,
'param_name' => 'files',
// Set the following option to 'POST', if your server does not support
// DELETE requests. This is a parameter sent to the client:
'delete_type' => 'DELETE',
'access_control_allow_origin' => '*',
'access_control_allow_credentials' => false,
'access_control_allow_methods' => array(
'OPTIONS',
'HEAD',
'GET',
'POST',
'PUT',
'PATCH',
'DELETE'
),
'access_control_allow_headers' => array(
'Content-Type',
'Content-Range',
'Content-Disposition'
),
.
.
.
.
.
I remain these lines untouched
.
.
.
protected function handle_file_upload($uploaded_file, $name, $size, $type, $error,
$index = null, $content_range = null) {
$file = new stdClass();
$file->name = $this->get_file_name($name, $type, $index, $content_range);
$file->size = $this->fix_integer_overflow(intval($size));
$file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index)) {
$clientid = $this->handle_form_clientid($file, $index);
$postid = $this->handle_form_postid($file, $index);
//Add the call to the database to add the data. Notice the three variables
//which are passed to the add_img function.
$this->add_img($file->name,$clientid,$postid);
//End of our additions. The code continues...
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
mkdir($upload_dir, $this->options['mkdir_mode'], true);
}
$file_path = $this->get_upload_path($file->name);
$append_file = $content_range && is_file($file_path) &&
$file->size > $this->get_file_size($file_path);
if ($uploaded_file && is_uploaded_file($uploaded_file)) {
// multipart/formdata uploads (POST method uploads)
if ($append_file) {
file_put_contents(
$file_path,
fopen($uploaded_file, 'r'),
FILE_APPEND
);
} else {
move_uploaded_file($uploaded_file, $file_path);
}
} else {
// Non-multipart uploads (PUT method support)
file_put_contents(
$file_path,
fopen('php://input', 'r'),
$append_file ? FILE_APPEND : 0
);
}
$file_size = $this->get_file_size($file_path, $append_file);
if ($file_size === $file->size) {
$file->url = $this->get_download_url($file->name);
list($img_width, $img_height) = @getimagesize($file_path);
if (is_int($img_width) &&
preg_match($this->options['inline_file_types'], $file->name)) {
$this->handle_image_file($file_path, $file);
}
} else {
//$file->size = $file_size;
$file->upload_to_db = $this->add_img($sid,$file->name);
if (!$content_range && $this->options['discard_aborted_uploads']) {
unlink($file_path);
$file->error = 'abort';
}
}
$this->set_additional_file_properties($file);
}
return $file;
}
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;
}
function add_img($sid,$whichimg,$caption,$view){
$add_to_db = $this->query("INSERT INTO gallery_pix (galx_sid,galx_file,galx_cap,galx_view) VALUES
('$sid','$whichimg','$caption','$view')") or die(mysql_error());
return $add_to_db;
}
function delete_img($delimg){
$delete_from_db = $this->query("DELETE FROM gallery_pix WHERE galx_sid='$delimg'") or die(mysql_error());
return $delete_from_db;
}
.
.
.
These lines remain untouched
.
.
.
public function delete($print_response = true) {
$file_name = $this->get_file_name_param();
$file_path = $this->get_upload_path($file_name);
$success = is_file($file_path) && $file_name[0] !== '.' && unlink($file_path);
if ($success) {
foreach($this->options['image_versions'] as $version => $options) {
if (!empty($version)) {
$file = $this->get_upload_path($file_name, $version);
if (is_file($file)) {
$this->delete_img($file_name);
unlink($file);
}
}
}
}
return $this->generate_response(array('success' => $success), $print_response);
}
}
我可以在没有数据库的情况下上传图片,但在这种情况下会淹没我几个小时。请让我离开这里。