The following examples are for versions of PHP 4 greater than 4.0.2. See the function entries for is_uploaded_file() and move_uploaded_file(). <?php // In PHP 4.1.0 or later, $_FILES should be used instead of $HTTP_POST_FILES. if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { copy($HTTP_POST_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file"); } else { echo "Possible file upload attack. Filename: " . $HTTP_POST_FILES['userfile']['name']; } /* ...or... */ move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file"); ?> The PHP script which receives the uploaded file should implement whatever logic is necessary for determining what should be done with the uploaded file. You can for example use the $HTTP_POST_FILES['userfile']['size'] variable to throw away any files that are either too small or too big. You could use the $HTTP_POST_FILES['userfile']['type'] variable to throw away any files that didn't match a certain type criteria. Whatever the logic, you should either delete the file from the temporary directory or move it elsewhere. The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.
我使用中文的变量名,就没有问题~
我使用中文的变量名,就没有问题~
move_uploaded_file
試一試
我没有用过move_uploaded_file
谢谢
// In PHP 4.1.0 or later, $_FILES should be used instead of $HTTP_POST_FILES.
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
copy($HTTP_POST_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack. Filename: " . $HTTP_POST_FILES['userfile']['name'];
}
/* ...or... */
move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
?>
The PHP script which receives the uploaded file should implement whatever logic is necessary for determining what should be done with the uploaded file. You can for example use the $HTTP_POST_FILES['userfile']['size'] variable to throw away any files that are either too small or too big. You could use the $HTTP_POST_FILES['userfile']['type'] variable to throw away any files that didn't match a certain type criteria. Whatever the logic, you should either delete the file from the temporary directory or move it elsewhere. The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.
我就用过中文名字的啊的上传文件了
不过不能超过2MB的<?
.
.
.
copy("$file","目录/$file_name");
unlink($file);
.
.
.
?>
我上传一个文件扩展名为.exe的文件,我给它起的名字是
“测试test.exe”,上传时没有问题在上传时,我用了个函数urlencode(),可我在将这个文件下载时它的文件名就变成了"test.exe",它自动就把“测试”省略了,那我怎么做才能使它的文件名部发生变化!!!!