简单上传PHP表格麻烦

时间:2014-10-20 07:54:01

标签: php pdf

嗨我正在尝试创建一个简单的上传php表单,但是当我上传pdf时,我在第8行收到错误消息,这是我的代码;

(代码更新)

<?php

 if(isset($_POST['submit']))
{
       $errors= array();
      $file_name = $_FILES['uploadFile']['name'];
       $file_size =$_FILES['uploadFile']['size'];
       $file_tmp =$_FILES['uploadFile']['tmp_name'];
       $file_type=$_FILES['uploadFile']['type'];   
       $value = explode(".", $file_name);
       $file_ext = strtolower(array_pop($value));

      $expensions= array("pdf");   
      if(in_array($file_ext,$expensions)== false)
      {
       $errors="Extension not allowed, please choose a PDF file.";
      }

      if($file_size > 9097152)
      {
      $errors[]='File size must be excately 2 MB';
      }    
      if(empty($errors)==true)
      {
       move_uploaded_file($file_tmp,"client_files/bond/uploads/".$file_name);
//include here insert query**
 echo "The file ".$file_name." has been uploaded.";
       //echo "Success";
      }
      else
      {
       print_r($errors);
      }
     }
    ?>

在我的html文件中,正文包含一个简单的表单;

  <div class="body"></div>
        <div class="grad"></div>
        <div class="header">
            <div>Logo<span>Here</span></div>
        </div>
        <br>
        <div class="login">
                <form action="upload.php" method="post" enctype="multipart/form-data">
  Please choose a file: <input type="file" name="uploadFile"><br>
  <input type="submit" value="Upload File">
</form>
        </div>

4 个答案:

答案 0 :(得分:0)

您应该在文件中定义$uploadFile_size变量。这将解决您的问题。

答案 1 :(得分:0)

    Try it
<?php

 if(isset($_POST['submit']))
{
       $errors= array();
      $file_name = $_FILES['uploadFile']['name'];
       $file_size =$_FILES['uploadFile']['size'];
       $file_tmp =$_FILES['uploadFile']['tmp_name'];
       $file_type=$_FILES['uploadFile']['type'];   
       $value = explode(".", $file_name);
       $file_ext = strtolower(array_pop($value));
       //$file_ext=strtolower(end(explode(".",$file_name))); -->this line wnt work bcoz only variable should be passed inside explode

      $expensions= array("pdf");   
      if(in_array($file_ext,$expensions)== false)
      {
       $errors="Extension not allowed, please choose a PDF file.";
      }

      if($file_size > 2097152)
      {
      $errors[]='File size must be excately 2 MB';
      }    
      if(empty($errors)==true)
      {
       move_uploaded_file($file_tmp,"uploads/".$file_name);

 echo "The file ".$file_name." has been uploaded.";
       //echo "Success";
      }
      else
      {
       print_r($errors);
      }
     }
    ?>

答案 2 :(得分:0)

try this
<div class="body"></div>
        <div class="grad"></div>
        <div class="header">
            <div>Logo<span>Here</span></div>
        </div>
        <br>
        <div class="login">
                <form action="upload.php" method="post" enctype="multipart/form-data">
  Please choose a file: <input type="file" name="uploadFile"><br>
  <input type="submit" name="submit" value="Upload File">
</form>
        </div>

答案 3 :(得分:0)

String Strtolower($ string)是原型。