上传大于2 MB的文件时出错

时间:2013-10-27 14:45:26

标签: php

我有2个php文件: 1 名称form_upload.php

 <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的图片时,它总是输出第二个。我做错了什么?

1 个答案:

答案 0 :(得分: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兆字节,您可以插入另一个值