duancheng8000 2015-11-25 05:41
浏览 18
已采纳

如果选择了文件,则上传文件,如果未选择,则在db中使用文件大小验证发送空值

I want to upload file if file is selected and if not selected then send null value in db and if file size is grater then 3 mb send alert msj to user and in that conduction do not update query in db. I have tried this code but having problem in condutional statement please help me out with this with suitable code my input type file tag name is AttachBills:

if(isset($_POST["AddUnit"])){
    echo "<script>alert(' in page subtion');</script>";

    function test_input($data)
        {
            $data = trim($data);
            $data = stripslashes($data);
            $data = htmlspecialchars($data);
            return $data;
        } 
    $InvoiceNumber=$StockName=$UnitsAdded=$TotalCost=$AttachBills=$PaymentMode=
    $PurchaseDate=$Comments="";

    $InvoiceNumber    =    test_input($_POST["InvoiceNumber"]);
    $StockName        =    test_input($_POST["StockName"]);
    $UnitsAdded       =    test_input($_POST["UnitAdded"]);
    $TotalCost        =    test_input($_POST["TotalCost"]);            
    $PaymentMode      =    test_input($_POST["PaymentMode"]);   
    $PurchaseDate     =    test_input($_POST["PurchaseDate"]);
    $Comments         =    test_input($_POST["Comments"]);
    $uploadOk         =    1;

    if($_FILES['AttachBills']['size'] > 0 ) {
        echo "<script>alert('their is a file attachbills');</script>";
        $Bill_File_Name=$_FILES["AttachBills"]["name"];
        $Bill_Tmp=$_FILES["AttachBills"]["tmp_name"];
        $Bill_Size=$_FILES["AttachBills"]["size"]/1024;

        if($Bill_Size<=200) {
            //New file name
            echo "<script>alert(' filesize is less then 200 coundutoion');</script>";
            //File upload path
            $Bill_Path="uploads/" . $Bill_File_Name;

            //function for upload file
            if(move_uploaded_file($Bill_Tmp,$Bill_Path)){
                $random=rand(1111,9999);
                $Attach_Name=$random.$Bill_File_Name; 
                echo "<script>alert(' in if moved coundution');</script>";
            } else {
                echo "<script>alert('Problem With FileUpload. Please Try Again');</script>";
            }
        } else {
            echo "<script>alert('Maximum upload file size limit is 200 kb');</script>";
            $uploadOk=0;
        }
    } else {
        if($uploadOk==1) {
            echo "<script>alert(' in uploodad ok 1');</script>";
            $UnitQuery="INSERT INTO `inventory_add_unit`(`InvoiceNumber`, `StockName`, `UnitsAdded`, `TotalCost`, `AttachBills`, `PaymentMode`, `PurchaseDate`, `Comments`) VALUES ('$InvoiceNumber','$StockName','$UnitsAdded','$TotalCost','$AttachBills','$PaymentMode','$PurchaseDate','$Comments')";
        }
    }
}
  • 写回答

1条回答 默认 最新

  • duanliexi1052 2015-11-25 06:19
    关注

    Possible error

    1. enctype="multipart/form-data" is missing
    2. php.ini might not have file_uploads = on set
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!