【发布时间】:2014-04-17 14:08:47
【问题描述】:
您好,有人可以告诉我为什么我的图片上传表单不起作用吗?经过严格的测试,我似乎无法将文件放到服务器上我上传的图像文件夹中。即使我已经大大增加了允许的文件大小,我仍然收到最大文件大小错误。
再次感谢
<?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"];
}
?>
【问题讨论】:
-
您是如何使用提交的 MAX_FILE_SIZE 的?我认为您可能需要增加 php.ini 中的 max_file_size var
-
您好,我没有 php.ini,老实说我不确定它是什么:/呵呵
-
不相关,但
($_FILES["file"]["size"] / 100000无法获取 kB。 -
你用的是什么服务器,能用
.htaccess文件吗?