上传表单中的错误

时间:2013-01-25 20:52:15

标签: php forms file-upload upload

你好我用上传进度条复制了1个上传文件源代码 它的工作如果我删除foreach并制作1个文件上传
但我想在我的表格中有5个文件字段
这是我现在的代码:

$upload_directory = "$fUllp/";
//5M
$allowsize = 5242880;
foreach($_FILES as $file) {
$n = $file['name'];
$s = $file['size'];
$t = $file['type'];
$tmp = $file['tmp_name'];
if (is_array($n)) {
  $c = count($n);
  for ($i=0; $i < $c; $i++) {
    if($s <= $allowsize){
    $filename = explode('.',$n);
    $filetype = $filename[1];

    if(!isset($filename[2])){
        $glast = mysql_query("select id from up_guest order by id desc limit 1");
        $flast = mysql_fetch_array($glast);
        if($flast['id'] == '' or $flast['id'] <= 0){
            $flast = 1;
        }
        else{
            $flast = $flast['id'] + 1;
        }
        $time = time();
        $filename = $flast.'.'.$filename[1];

        if(in_array($t,$allow)){

            if (move_uploaded_file($tmp, $upload_directory . $filename)) {
                //insert db
                //img full
                $fullurl = $siteurl.'/'.$upload_directory.$filename;
                //for sql
                $fullurlsq = '/'.$upload_directory.$filename;
                $fullurlsqt = '/'.$upload_directory.'t/'.$filename;
                //img resize
                $image = new SimpleImage();
                $image->load($upload_directory.'/'.$filename);
                $image->resizeToHeight(100);
                $image->resizeToWidth(100);
                $image->save($upload_directory.'/t/'.$filename);
                //img koochik
                $imgt = $upload_directory.'/t/'.$filename;
                mysql_query("insert into up_guest(name,name_t,type,time,ip) values('$fullurlsq','$fullurlsqt','$filetype',$time,'$ip')");
                print '<br><div class="system-message"><ul class="index_info"><li>توضیح: <span>فایل با موفقیت آپلود شد<bR /><div class="thumb_img">';
                print "<a href=\"$fullurl\" onclick=\"window.open(this.href,\"_blank\");return false;\"><img src=\"$imgt\"></a></div>";
                //tbl1
                print '<table border="0" width="100%" cellspacing="0" cellpadding="0" class="up_box_input"><tbody><tr><td class="btitle">لینک تصویر کوچک</td><td class="all_box_link"><textarea readonly="readonly" rows="2" cols="40" class="up_input" tabindex="1" onclick="this.select();">';
                print "[url=$siteurl/][img]$imgt [/img][/url]</textarea></td></tr></tbody></table>";
                //tbl2
                print 'echo file detaid for user';

            }//file upload she
            else{
                echo '<div class="site_error_msg">cant up</div>';
            }
        }//age allow bood un file
        else{
            echo '<div class="site_error_msg">extention not allowed</div>';
        }
    }//if noghte vasatesh nabood
    else{
        echo '<div class="site_error_msg">you not must have . in file name</div>';
    }
}//if sizesh mojaz bood
else{
    echo '<div class="site_error_msg">uploaded file is more than 5 MB</div>';
}//end my code

但 它在第一个IF中运行 我的意思是

if(in_array($t,$allow)){

并运行此其他

else{
    echo '<div class="site_error_msg">uploaded file is more than 5 MB</div>';
}//end my code

所以它必须有问题 这些行及其设置文件名大小incorect

foreach($_FILES as $file) {
$n = $file['name'];
$s = $file['size'];
$t = $file['type'];
$tmp = $file['tmp_name'];
if (is_array($n)) {
  $c = count($n);
  for ($i=0; $i < $c; $i++) {

1 个答案:

答案 0 :(得分:0)

好吧找到我的不成功的问题!我必须在我的文件大小和名称下填写For like this

foreach($_FILES as $file) {
$n = $file['name'];
$s = $file['size'];
$t = $file['type'];
$tmp = $file['tmp_name'];
if (is_array($n)) {
  $c = count($n);
  for ($i=0; $i < $c; $i++) {
      $ss = $s[$i];
      $tmpp = $tmp[$i];
      $nn = $n[$i];
      $tt = $t[$i];
    if($ss <= $allowsize){
    $filename = explode('.',$nn);
    $filetype = $filename[1];

    if(!isset($filename[2])){
        $glast = mysql_query("select id from up_guest order by id desc limit 1");
        $flast = mysql_fetch_array($glast);
        if($flast['id'] == '' or $flast['id'] <= 0){
            $flast = 1;
        }
        else{
            $flast = $flast['id'] + 1;
        }
        $time = time();
        $filename = $flast.'.'.$filename[1];

        if(in_array($tt,$allow)){

谢谢大家:D