我想获得jQuery文件上传的帮助,如果我的英语不正确,我很抱歉我想通过URL或一些隐藏字段传递ID参数来显示图像,因为我有一个画廊,每个画廊都有它的图像。
<div class="container-fluid">
<!-- The file upload form used as target for the file upload widget -->
<!-- estava assim action="//jquery-file-upload.appspot.com/"-->
<form id="fileupload" action="server/php/UploadHandler" method="POST" enctype="multipart/form-data">
<!-- Redirect browsers with JavaScript disabled to the origin page -->
<noscript>
<input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/">
</noscript>
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="row fileupload-buttonbar">
<div class="col-lg-7">
<!-- The fileinput-button span is used to style the file input field as button -->
<!--the hidden input is used to get id by GET in the parameter to urledit= -->
<input type="hidden" name="urledit" value="<?php echo $urledit; ?>">
<span class="btn btn-success fileinput-button">
<i class="glyphicon glyphicon-plus"></i>
<span>Add fotos...</span>
<input type="file" name="files[]" multiple>
</span>
<button type="submit" class="btn btn-primary start">
<i class="glyphicon glyphicon-upload"></i>
<span>Iniciar upload</span>
</button>
<button type="reset" class="btn btn-warning cancel">
<i class="glyphicon glyphicon-ban-circle"></i>
<span>Cancelar upload</span>
</button>
<button type="button" class="btn btn-danger delete">
<i class="glyphicon glyphicon-trash"></i>
<span>Apagar</span>
</button>
<input type="checkbox" class="toggle">
<!-- The global file processing state -->
<span class="fileupload-process"></span>
</div>
<!-- The global progress state -->
<div class="col-lg-5 fileupload-progress fade">
<!-- The global progress bar -->
<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-bar progress-bar-success" style="width:0%;"></div>
</div>
<!-- The extended global progress state -->
<div class="progress-extended"> </div>
</div>
</div>
<!-- The table listing the files available for upload/download -->
<table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>
</form>
</div>
数据库类:
<?php
include_once 'config.php';
class conn extends config
{
var $pdo;
function __construct()
{
$this->pdo = new PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->user, $this->pass);
}
function getImages($urledit)
{
//$urledit = '9';
$stm = $this->pdo->prepare("SELECT gallery_img FROM site_gallery WHERE gallery_galeria_id = '$urledit'");
$run = $stm->execute();
$array = array();
while ($rs = $stm->fetch(PDO::FETCH_ASSOC)) {
array_push($array,$rs['gallery_img']);
}
return $array;
}
function deleteImages($foto)
{
$stm = $this->pdo->prepare("DELETE FROM site_gallery WHERE gallery_img = :foto");
$stm->bindValue(":foto",$foto);
$run = $stm->execute();
}
function insertImages($id,$foto,$data)
{
try{
$stm = $this->pdo->prepare("INSERT INTO site_gallery (gallery_galeria_id, gallery_img, gallery_data) VALUES (:id,:foto,:data)");
$stm->bindValue("id",$id);
$stm->bindValue("foto",$foto);
$stm->bindValue("data",$data);
$run = $stm->execute();
//echo $stm->rowCount();
}catch(PDOException $e){
echo 'Error: '. $e->getMessage();
}
}
}
?>
UploadHandler.php 插入数据库工作
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($uploaded_file, $name, $size, $type, $error,
$index, $content_range);
$file->size = $this->fix_integer_overflow((int)$size);
$file->type = $type;
if ($this->validate($uploaded_file, $file, $error, $index)) {
$this->handle_form_data($file, $index);
$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);
//insere no banco
$data = date('Y-m-d H:i:s');
$urledit = $this->get_url_edit('urledit');
$conn = new conn();
$conn->insertImages($urledit,$file->name,$data);
$conn->getImages($urledit);
}
} else {
// Non-multipart uploads (PUT method support)
file_put_contents(
$file_path,
fopen('php://input', 'r'),
$append_file ? FILE_APPEND : 0
);
}
但是这个选择不起作用:
protected function get_file_objects($iteration_method = 'get_file_object') {
$upload_dir = $this->get_upload_path();
if (!is_dir($upload_dir)) {
return array();
}
$urledit = $this->get_url_edit('urledit');
//$urledit = '9';
$conn = new conn();
$Images = $conn->getImages($urledit);
return array_values(array_filter(array_map(
array($this, $iteration_method),
//scandir($upload_dir)
$Images
)));
}
因为它没有值$ Images = $ conn-&gt; getImages($ urledit);
任何人都可以帮助我吗? Alguémpoderiame ajudar? pode seremportuguêstambém。