2013-10-27 191 views
0

我有2個PHP文件:名form_upload.php錯誤上傳文件大於2 MB

<html> 
    <head><title>File Upload</title></head> 
    <body> 
    <ol> 
     <li>Enter the file name of the product picture you want to upload or the the browse button to navigate to the picture file</li> 
     <li>when the path to the picture file shows in the text field, click the upload picture</li> 
    </ol> 

    <form enctype="multipart/form-data" action="uploadFile.php" method="POST"> 
    <input type="hidden" name="MAX_FILE_SIZE" value="500000"/> 
    <input type="file" name="pix" size="60"/> 
    <p><input type='submit' name="Upload" value="Upload picture"/></p> 
    </form> 
    </body> 
    </html> 

第二:uploadFile.php

<?php 

if(!isset($_POST['Upload'])) 
{ 
    include("form_upload.php"); 
} 
else 
{ 
    if($_FILES['pix']['tmp_name']=="none") 
    { 
     echo "file did not successfully upload. Check the file size. File must be less than 500K"; 
     include("form_upload.php"); 
     exit(); 
    } 
    if(!preg_match("/image\/jpeg/",$_FILES['pix']['type'])) 
    { 
     echo "only jpg files are allowed. Please try another file"; 
     include("form_upload.php"); 
     exit(); 
    } 
    else 
    { 
     $destination='C:\xampp\htdocs\test\hinh\ '.$_FILES['pix']['name']; 
     $temp_file=$_FILES['pix']['tmp_name']; 
      move_uploaded_file($temp_file,$destination); 
     echo "<p>the file has successfully uploaded :{$_FILES['pix']['name']} {$_FILES['pix']['type']} ({$_FILES['pix']['size']}) </p>"; 


    } 
} 

我不能輸出的第一個語句。當我上傳大於2MB的圖片時,它總是輸出第二張圖片。我做錯什麼了嗎 ?

+0

'if($ _ FILES ['pix'] ['tmp_name'] ==「none」)' - 這與文件大小有關? –

+0

很可能是一個主機設置....默認限制通常是2兆 – charlietfl

+0

請注意,MAX_FILE_SIZE設置僅僅是對應用程序客戶端用戶的便利功能。 '但是,PHP設置(在服務器端)的最大尺寸,不能被愚弄。[doc](http://php.net/manual/en/features.file-upload.post-method.php) – raina77ow

回答

0

添加

php_value upload_max_filesize 10M 
php_value post_max_size 10M 

htaccess的

或更改此值

upload_max_filesize = 10M 
post_max_size = 10M 

php.ini中

,並重新啓動Web服務器

10M表示10兆字節,可以插入其他值

+2

當然假設主機允許訪問php.ini或允許htaccess覆蓋 – charlietfl

相關問題