php - 使用uploadify上传文件 [英] php - file uploads using uploadify

查看:114
本文介绍了php - 使用uploadify上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用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']);


$ b $ 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']; 


解决方案

  $ tblQry ='INSERT INTO tbl_files'; 
$ tblQry。='SET
post_id ='。$ _ SESSION ['post_id']。',
filename ='。$ name2。',
file_data ='。$ data2。',
mime_type_id ='。$ mime2。'';
$ db-> query($ tblQry);


I'm having problems with uploadify. Whenever I use a string in the $post_id, uploadify only uploads a single file when I've selected 3 files for upload. But when I specify a non-existing value for $post_id such as a session variable that doesn't exist $_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.

 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,

echo $_FILES['Filedata']['name'];

解决方案

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);

这篇关于php - 使用uploadify上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆