图像上传表单获取最大文件大小错误

时间:2014-04-17 14:08:47

标签: php image forms webforms

您好,有人可以告诉我为什么我的图片上传表格不起作用?经过严格的测试后,我似乎无法将文件存入服务器上的上传图像文件夹。即使我已经大大增加了文件大小,我仍然会收到最大文件大小错误。

再次感谢

<?php

// filename: upload.form.php

// first let's set some variables

// make a note of the current working directory relative to root.
$directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

// make a note of the location of the upload handler
$uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'multiple.upload.processor.php';

// set a max file size for the html upload form
$max_file_size = 30000; // size in bytes

// now echo the html page
?>


<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

    <link rel="stylesheet" type="text/css" href="stylesheet.css">

    <title>Upload form</title>

</head>

<body id="body">

<form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">

    <h1>
        Sell-A-Car
    </h1>

    <p>
        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
    </p>

    <p>
        <label for="file1">Item Image 1:</label>
        <input id="file1" type="file" name="file[]">
    </p>

    <p>
        <label for="file2">Item image 2:</label>
         <input id="file2" type="file" name="file[]">
    </p>

    <p>
        <label for="file3">Item image 3:</label>
        <input id="file3" type="file" name="file[]">
    </p>

    <p>
        <label for="submit">Press to...</label>
        <input id="submit" type="submit" name="submit" value="SELL IT!">
    </p>

</form>


</body>

</html>

第二个php文件是

<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 100000) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>

1 个答案:

答案 0 :(得分:2)

文件大小错误是指您的PHP配置。如果您使用的是共享托管但无法修改php.ini,请尝试以下操作:

在PHP脚本的头部添加这些行

ini_set("post_max_size","64M");
ini_set("upload_max_filesize","64M");

如果不起作用,请在应用程序的主文件夹中创建.htaccess文件并添加

php_value    upload_max_filesize    64M
php_value    post_max_size    64M