【发布时间】:2014-07-28 19:22:48
【问题描述】:
下面我提到了 AJAX 脚本,我想在上传时为每张照片附加数据库中的 id。但是在下面的脚本中使用“var m='_'+x;”时没有得到记录的数据库 id(当我打印它时,它显示为空白)。那么如何检索一行的数据库 id 并附加到 AJAX 脚本中?照片被上传并使用 id 存储在提到的文件夹中。但是在当我检查它显示的页面源时,该页面。ID 没有在中间加载。
$(function(){
var btnUpload=$('#me');
var mestatus=$('#mestatus');
var files=$('#files');
new AjaxUpload(btnUpload, {
action: 'uploadPhoto.php',
name: 'uploadfile',
onSubmit: function(file, ext)
{
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// extension is not allowed
mestatus.text('Only JPG, PNG or GIF files are allowed');
return false;
}
mestatus.html('<img src="ajax-loader.gif" height="16" width="16" align="left">');
},
onComplete: function(file, response){
// alert(response)
//On completion clear the status
mestatus.text('');
//On completion clear the status
files.html('');
//Add uploaded file to list
if(response==="success")
{
var x=file;
var m='<?=$data44[id]?>_'+x;
document.getElementById('img_name').value=x;
$('<li></li>').appendTo('#files').html('<img src="photo/demophoto_'+m+'" alt="" height="110px" width="95px" /><br />').addClass('success');
} else{
$('<li></li>').appendTo('#files').text(file).addClass('error');
}
}
});
});
上传照片.php
include_once("db.php");
$sel="select usnno from usn where id='$_SESSION[lgkey]'";
$qry=mysql_query($sel) or die(mysql_error());
$row=mysql_fetch_array($qry);
$sel44=mysql_query("select * from reg_form where usn='$row[usnno]' ");
$data44=mysql_fetch_array($sel44);
$uploaddir = './photo/';
$file = $uploaddir ."demophoto_".$data44['id'].'_'.basename($_FILES['uploadfile']['name']);
$file_name= "demophoto_".$data44['id'].'_'.$_FILES['uploadfile']['name'];
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
echo "success";
} else {
echo "error";
}
【问题讨论】:
-
艾伦请。 Y U NO 显示 uploadPhoto.php 代码?
-
我添加了uploadphoto.php
-
也许您应该首先以某种方式将图像实际存储在数据库中。
-
照片被上传并存储在带有 id 的指定文件夹中,但是在前端升级后,当我在 php 中按更新时,它不会在该 AJAX 脚本中加载 id 它存储没有 id 的路径,所以它不会被正确加载..
-
不应该是 var m='=$data44['id']?>_'+x;而不是 var m='=$data44[id]?>_'+x; ?那么在 id 之间添加 (') 呢?