从手机上传图片时出错

时间:2017-02-11 21:34:39

标签: javascript php html

我上传图片,如果我使用的是电脑,它可以正常工作,但如果我使用的是手机,则会说:

  

抱歉,上传您的单据时出错了

<?php
     if(isset($_POST["imagea"]) || isset($_POST["imageb"]) || isset($_POST["imagec"]) || isset($_POST["imaged"])){
                    $post_image = "";
                    if(isset($_POST["imagea"])){
                        $post_image = $paying[1];
                    }
                    else if(isset($_POST["imageb"])){
                        $post_image = $paying[2];
                    }
                    else if(isset($_POST["imagec"])){
                        $post_image = $paying[3];
                    }
                    else if(isset($_POST["imaged"])){
                        $post_image = $paying[4];
                    }
                    else if(isset($_POST["imagee"])){
                        $post_image = $paying[5];
                    }
                    else if(isset($_POST["imagef"])){
                        $post_image = $paying[6];
                    }
                    else if(isset($_POST["imageg"])){
                        $post_image = $paying[7];
                    }
                    else if(isset($_POST["imageh"])){
                        $post_image = $paying[8];
                    }
                    else if(isset($_POST["imagei"])){
                        $post_image = $paying[9];
                    }
                    else if(isset($_POST["imagej"])){
                        $post_image = $paying[10];
                    }

                    echo "uploading $post_image";

                   $target_dir = "uploads/";
                    $target_file = $target_dir . basename($_FILES["slip"]["name"]);

                    $uploadOk = 1;
                    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
                    // Check if image file is a actual image or fake image
                    if(1) {

                    // Check file size
                    if ($_FILES["slip"]["size"] > 5000000) {
                        echo '  <script type="text/javascript">';
                        echo '     alert("Sorry, your file is too large.");';
                        echo "   window.location.href = window.location.href;";
                        echo '   </script>';
                        $uploadOk = 0;
                    }
                    // Allow certain file formats
                    else if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
                    && $imageFileType != "gif" ) {
                        echo '  <script type="text/javascript">';
                        echo '     alert("Sorry, only JPG, JPEG, PNG & GIF or non empty files are allowed..");';
                        echo "   window.location.href = window.location.href;";
                        echo '   </script>';
                        $uploadOk = 0;
                    }
                    // Check if $uploadOk is set to 0 by an error
                    if ($uploadOk == 0) {

                            echo '  <script type="text/javascript">';
                            echo '     alert("Sorry, your file was not uploaded.");';
                            echo "   window.location.href = window.location.href;";
                            echo '   </script>';
                    // if everything is ok, try to upload file
                    } else {
                        include "connect.php";
                        $mem_no = $_COOKIE['mem_no'];

                        $slip_id = get_slip_id() + 1;
                        //$paying = get_slip_rec($mem_no);
                        $today = date('y-m-d');
                        $slip_name = $mem_no."".$post_image;

                        $target_file = "uploads/$slip_name.jpg";
                        if (move_uploaded_file($_FILES["slip"]["tmp_name"], $target_file)) {
                            if(!slip_exisists("$target_file")){
                                $sql = "insert into table (slip_id,slip_name,poster,receiver,slip_status,slip_date) values($slip_id,'$slip_name','$mem_no','$post_image','pending','$today')" ;
                                $result = mysqli_query($conn,$sql);
                            }
                            echo "errorf ".mysqli_error($conn);
                            echo '<script type="text/javascript">';
                            echo 'alert("your deposit slip have been successfully uploaded please wait for your payment to be confirmed");';
                            echo "   window.location.href = window.location.href;";
                            echo '   </script>';
                        } else {
                            echo '  <script type="text/javascript">';
                            echo '     alert("Sorry, there was an error uploading your slip.");';
                            echo "   window.location.href = window.location.href;";
                            echo '   </script>';

                        }
                    }
                }



            function slip_exisists($slip_name){
                    include "connect.php";
                    $sql = "select * from slip where slip_name = $slip_name and slip_status = 'pending'";

                    $result = mysqli_query($conn,$sql);

                    if($result){
                            return true;
                    }
                    else{
                        return false;
                    }
                }
                function get_slip_id(){
                    include "connect.php";
                    $sql = "select slip_id from slip order by slip_id desc";

                    $result = mysqli_query($conn,$sql);

                    if(mysqli_num_rows($result) > 0){
                            $row = mysqli_fetch_array($result,MYSQLI_NUM);
                            return $row[0];
                    }
                    else{
                        return 1;
                    }

                }


                function get_slip_rec($mem_noi){
                    include "connect.php";
                    $sql = "select mem_no from pay_request, req_hist where paying member = '$mem_noi' and pay_request.request_code = req_hist.request_code";

                    $result = mysqli_query($conn,$sql);

                    if(mysqli_num_rows($result) > 0){   
                            $row = mysqli_fetch_array($result,MYSQLI_NUM);
                            return $row[0];
                    }
                    else{
                        return '404';
                    }

                }
     }
?>

0 个答案:

没有答案