[英]php - file uploads using uploadify
I'm having problems with uploadify. 我在使用uploadify时遇到了问题。 Whenever I use a string in the $post_id, uploadify only uploads a single file when I've selected 3 files for upload.
每当我在$ post_id中使用字符串时,uploadify只会在我选择3个文件进行上传时上传单个文件。 But when I specify a non-existing value for $post_id such as a session variable that doesn't exist $_SESSION['something'].
但是当我为$ post_id指定一个不存在的值时,例如一个不存在的会话变量$ _SESSION ['something']。 It inserts all three of the files into the database.
它将所有三个文件都插入到数据库中。 I'm thinking that this might be an error on the data structure of $post_id.
我认为这可能是$ 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'");
}
I tried to echo the rest of the data and it seems like they're only storing plain strings. 我试图回应其余的数据,看起来他们只存储纯字符串。 So $post_id string should also work,
所以$ post_id字符串也应该有效,
echo $_FILES['Filedata']['name'];
If you are using sessions, please check that you have started session ie session_start() 如果您正在使用会话,请检查您是否已启动会话,即session_start()
If you want to pass the post_id from uploadify function to php file, you can use the scriptData, which is mentioned in the below function. 如果要将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 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'");
}
Try this it should work as you expected 试试这个它应该按预期工作
$tblQry = 'INSERT INTO tbl_files ';
$tblQry .= 'SET
post_id = "' .$_SESSION['post_id'] . '",
filename = "' .$name2. '",
file_data = "' .$data2.'",
mime_type_id = "' .$mime2.'"';
$db->query($tblQry);
Just encountered this problem. 刚遇到这个问题。 Flash doesn't use the cookies that are set in your browser so you need to pass your session id into the flash script as a post variable and then set the cookie value from the post value in your upload.php script.
Flash不使用浏览器中设置的cookie,因此您需要将会话ID作为post变量传递到flash脚本中,然后在upload.php脚本中的post值中设置cookie值。 See:
看到:
jQuery and Uploadify session in the php file php文件中的jQuery和Uploadify会话
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.