首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像文件上传-No文件上传错误

图像文件上传-No文件上传错误
EN

Stack Overflow用户
提问于 2014-09-23 17:11:24
回答 1查看 122关注 0票数 1

我正在尝试上传图片文件到我的php服务器。我使用JavaScript来选择文件浏览的button.the选择按钮,然后显示所选的图像,当我尝试将图像上传到服务器时,它抛出错误php错误:

代码语言:javascript
复制
Array
(
    [image] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

)

html页面代码

代码语言:javascript
复制
<div style="height:0px;overflow:hidden"><form id="myForm" action="http://192.168.2.4/digiid/webapi/capturehtml.php" method="post" enctype="multipart/form-data">
                    <input type="file" name="image" id="file"/>

            </div>
                    <a class="button1" id="browseButton" onclick="chooseFile()"  style="width:12%;height: 30px; text-decoration:none;"><font color="white" size="5px">Select ID</font></a>
        <br/>
    <img src='' id='imgscreen'  width='200' height='200'>
                    <div>
    <a class="button1"onclick="myFunction()" style= " width:12%;height: 30px; text-decoration:none;"><font color="white" size="5px">Save ID</font></a></form>

                      </div>    <script>
                    function myFunction() {
                        document.getElementById("myForm").submit();
                    }
                </script>
    <script>
    var imgScreen = document.getElementById("imgscreen");
    var audioPlayBtn = document.getElementById("playaudioButton");
    //var inputField = document.getElementById("audioURL");
    var browseButton = document.getElementById("browseButton");
    var x;

    var fileSelector = document.createElement('input')

    fileSelector.setAttribute("type", "file");
    fileSelector.setAttribute("accept","image/*");


    browseButton.onclick = function () {
        fileSelector.click();
        return false;
    };
    function chooseFile() {
     x=  document.getElementById("file").click();
        fileSelector(x);
    };

    fileSelector.onchange = function (x) {
        x = window.URL.createObjectURL(this.files[0]);
        if (x!=null) {
            //  only load a video file when the text field changes

                imgScreen.src = x;
           /* var fu1 = document.getElementById("FileUpload1");
            alert("You selected " + fu1.value);*/


            var path = x;
           var fileName = path.match(/[^\/\\]+$/);
          //  alert("  "+fileName);
            document.getElementById("audioURL").innerHTML=filename.value;


            imgScreen.load();
        }
    };</script>

php代码

代码语言:javascript
复制
echo "<pre>";
print_r($_FILES);
//error_reporting(9);
$filePath = $_FILES['image']['tmp_name'];
$fileName = $_FILES['image']['name'];
$userid=32;//$_SESSION["userid"];
if(!empty($filePath)){
$data = array('userid' => $userid, 'file' => "@$filePath", 'fileName' =>$fileName,'filename'=>$fileName);
    $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://192.168.2.4/digiid/api/addid.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4);

if(curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 4)){

//file_get_contents('php://input');
    $json =curl_exec($ch);
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if($httpcode==200){
        if($json!=null){
            $decoded=json_decode($json,true);
            $code= $decoded["code"];
            //    $userid=$decoded["userid"];
            if($code==0){
                header( 'Location: ./list.php' );

            }else{
                header( 'Location: ./capture.html' );
            }
        }
    }else{
        header( 'Location: ./notfound1.html' );

    }
}else{
    header( 'Location: ./notfound1.html' );

}
    curl_close($ch);
}
EN

回答 1

Stack Overflow用户

发布于 2014-09-23 17:17:43

您是否可以在php脚本中执行var_dump($_POST);来查看发布到服务器的内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25991189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档