我在使用uploadify时遇到了问题。每当我在$ post_id中使用字符串时,uploadify只会在我选择3个文件进行上传时上传单个文件。 但是当我为$ post_id指定一个不存在的值时,例如一个不存在的会话变量$ _SESSION ['something']。它将所有三个文件都插入到数据库中。我认为这可能是$ post_id的数据结构上的错误。
if(!empty($_FILES)){
$post_id = 'aa';
$name2 = mysql_real_escape_string($_FILES['Filedata']['name']);
$mime2 = mysql_real_escape_string($_FILES['Filedata']['type']);
$data2 = mysql_real_escape_string(file_get_contents($_FILES['Filedata']['tmp_name']));
$size2 = intval($_FILES['Filedata']['size']);
$db->query("INSERT INTO tbl_files SET post_id='$post_id', filename='$name2', file_data='$data2', mime_type_id='$mime2'");
}
我试图回显剩下的数据,看起来他们只存储普通的字符串。所以$ post_id字符串也应该有效,
echo $_FILES['Filedata']['name'];
答案 0 :(得分:1)
如果您正在使用会话,请检查您是否已启动会话,即session_start()
如果你想将post_id从uploadify函数传递给php文件,你可以使用scriptData,这在下面的函数中提到。
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//uploadify function
$("#file_upload").uploadify({
'uploader': 'uploadify.swf',
'script': 'uploadify.php',
'cancelImg': 'cancel.png',
'folder': 'photos', //folder where images to be uploaded
'auto': false, // use for auto upload
'multi': true,
'queueSizeLimit': 6,
'buttonImg': 'images/upload.png',
'width': '106',
'height': '33',
'wmode': 'transparent',
'method': 'POST',
'scriptData': {'myid':post_id}, //you can post the id here
'onQueueFull': function(event, queueSizeLimit) {
alert("Please don't put anymore files in me! You can upload " + queueSizeLimit + " files at once");
return false;
},
'onComplete': function(event, ID, fileObj, response, data) {
$("#uploadfiles").append(response+",");
},
'onAllComplete': function(response, data) {
showAll();
}
});
</script>
<强> uploadify.php 强>
if (!empty($_FILES)) {
$post_id = $_POST['myid'];
include_once "config.php";
//use this when uploading images into a folder
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$fna = $_FILES['Filedata']['name'];
$targetFile = str_replace('//','/',$targetPath) . $fna;
move_uploaded_file($tempFile,$targetFile);
//folder upload end
$name2 = mysql_real_escape_string($_FILES['Filedata']['name']);
$mime2 = mysql_real_escape_string($_FILES['Filedata']['type']);
$data2 = mysql_real_escape_string(file_get_contents($_FILES['Filedata']['tmp_name']));
$size2 = intval($_FILES['Filedata']['size']);
$db->query("INSERT INTO tbl_files SET post_id='$post_id', filename='$name2', file_data='$data2', mime_type_id='$mime2'");
}
答案 1 :(得分:1)
试试这个应该按预期工作
$tblQry = 'INSERT INTO tbl_files ';
$tblQry .= 'SET
post_id = "' .$_SESSION['post_id'] . '",
filename = "' .$name2. '",
file_data = "' .$data2.'",
mime_type_id = "' .$mime2.'"';
$db->query($tblQry);
答案 2 :(得分:0)
刚遇到这个问题。 Flash不使用浏览器中设置的cookie,因此您需要将会话ID作为post变量传递到Flash脚本中,然后在upload.php脚本中的post值中设置cookie值。参见: