2014-10-20 87 views
0

嗨我試圖創建一個簡單的上傳PHP表單,但是當我上傳PDF我收到第8行的錯誤消息,這裏是我的代碼;簡單上傳PHP表單問題

(代碼更新)

<?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> 
+0

定義了「$ pdf」嗎? – 2014-10-20 07:55:50

+0

什麼是確切的錯誤消息,你在哪裏定義了'$ pdf'? – Rizier123 2014-10-20 07:58:47

+0

致命錯誤:調用第8行的/public_html/bond/upload.php中的非對象的成員函數Output(),我感覺它的原因$ pdf未定義我需要添加到pdf中以定義什麼它? – user3607744 2014-10-20 08:00:11

回答

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> 
0

您應該在文件中定義$uploadFile_size變量。這將解決您的問題。

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); 
     } 
    } 
    ?> 
+0

我已經將它添加到服務器,並用舊的php代碼替換它,但它現在還沒有上傳pdf或顯示任何錯誤消息? – user3607744 2014-10-20 08:34:42

+0

?我將PHP加載到服務器上,它完成了整個上傳..%但是當它完成後它變成空白,並且不會將pdf上傳到服務器? – user3607744 2014-10-20 08:52:20

+0

任何想法爲什麼它可能不工作我的結局? – user3607744 2014-10-20 09:19:10

0

字符串用strtolower($字符串)的原型。