twitter-bootstrap PHP 文件上传 - 没有文件上传错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15614598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:43:35  来源:igfitidea点击:

PHP File Uploading - No File Uploaded Error

phphtmlformstwitter-bootstrap

提问by acme

I've created an image uploading form , using twitter bootstrap and the jansy extention, using the next code section:

我创建了一个图像上传表单,使用 twitter bootstrap 和 jansy 扩展,使用下一个代码部分:

     <form action="fileName.php" method="post" enctype="multipart/form-data">
         <div class="fileupload fileupload-new" data-provides="fileupload">
          <div class="fileupload-preview thumbnail" style="width: 200px; height: 150px;"></div>
          <div>
            <span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" name="pic" id="pic"/></span>
            <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
            <button type="submit" class="btn">Upload</button>
          </div>
      </form>

on the fileName.php the following code is executed:

在 fileName.php 上执行以下代码:

print_r($_FILES);
if($_FILES["pic"]["error"] > 0){ /*image uploading has failed*/
        echo "Error occured ".$_FILES["pic"]["error"];  
    }
else {
    echo "image was uploaded successfully";
}

and returns the next message :

并返回下一条消息:

Array ( [pic] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) Error occured 4

How come the file is not uploaded ? How could I solve this?

文件怎么没有上传?我怎么能解决这个问题?

Thanks.

谢谢。

回答by acme

Error 4 means UPLOAD_ERR_NO_FILE, so no file has been posted. I'd say the problem is somewhere in your javascript code or the components you used. Is any JavaScript error thrown?

错误 4 表示UPLOAD_ERR_NO_FILE,因此尚未发布任何文件。我会说问题出在您的 javascript 代码或您使用的组件中。是否抛出任何 JavaScript 错误?

Try a simple

尝试一个简单的

<form action="fileName.php" method="post" enctype="multipart/form-data">
    <input type="file" name="pic"> 
</form>

to see if it works without any JavaScript plugins.

看看它是否在没有任何 JavaScript 插件的情况下工作。