我在Windows2008的IIS下安装了PHP,上传文件总是失败test.html<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="test.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
test.php<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}echo 'Here is some more debugging info:';
print_r($_FILES);print "</pre>";?>
PHP.ini中相关设置; Whether to allow HTTP file uploads.
file_uploads = On; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir =C:\UploadTmp; Maximum allowed size for uploaded files.
upload_max_filesize = 10M
其中C:\UploadTmp和C:\MyWeb\var\www\uploads权限已设置为IUSR用户可读可写。现在我的问题是
1、test.php中的$uploaddir = '/var/www/uploads/'路径是相对于test.php吗? 如果test.php的路径是C:\MyWeb\test.php,那么$uploaddir是C:\MyWeb\var\www\uploads吗?2、可能是原因导致上传总是失败
<form enctype="multipart/form-data" action="test.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
test.php<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}echo 'Here is some more debugging info:';
print_r($_FILES);print "</pre>";?>
PHP.ini中相关设置; Whether to allow HTTP file uploads.
file_uploads = On; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir =C:\UploadTmp; Maximum allowed size for uploaded files.
upload_max_filesize = 10M
其中C:\UploadTmp和C:\MyWeb\var\www\uploads权限已设置为IUSR用户可读可写。现在我的问题是
1、test.php中的$uploaddir = '/var/www/uploads/'路径是相对于test.php吗? 如果test.php的路径是C:\MyWeb\test.php,那么$uploaddir是C:\MyWeb\var\www\uploads吗?2、可能是原因导致上传总是失败
最好加上$_SERVER['DOCUMENT_ROOT']
你以上的代码是php相级目录下的var文件夹
我猜可能是不存在造成的,你可以建个试试var下面还有www