w3school的PHP教程提炼(二)PHP高级
2010-12-09 07:16:02 来源:WEB开发网核心提示:4.4 保存被上传的文件将上面例子在临时文件夹创建的被上传文件的临时副本拷贝到另外的位置以免其在脚本结束时消失Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?p
4.4 保存被上传的文件
将上面例子在临时文件夹创建的被上传文件的临时副本拷贝到另外的位置以免其在脚本结束时消失
<?php
if((($_FILES["file"]["type"] == "images/gif"|| $_FILES["file"]["type"] == "images/jpeg"|| $_FILES["file"]["type"] == "images/pjpeg"))&& ($_FILES["file"]["size"] < 20000)){ //IE识别jpg为pjpeg,FF识别jpg为jpeg
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"] /1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if(file_exists("upload/" . $_FILES["file"]["name"])){
echo $_FILES["file"]["name"] . "already exists. ";
}else{
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}else{
echo "Invalid file";
}
?>
[]
赞助商链接