php代碼:<!DOCTYPE?html>
<html>
<head>
<meta?charset="utf-8">
<title></title>
</head>
<body>
<?php??
????session_start();??
????$_SESSION["userid"]="zxh";??
????if?(1)
????{??
????????if?($_FILES["file"]["error"]?>?0)??
????????{??
????????????echo?"Return?Code:?"?.?$_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?/>";//獲取文件臨時地址??
????????????
????????????//自定義文件名稱??
????????????$array=$_FILES["file"]["type"];??
????????????$array=explode("/",$array);??
????????????$newfilename="new_name";?
????????????$_FILES["file"]["name"]=$newfilename.".".$array[1];??
??????????????
????????????if?(!is_dir("new_bigo"))//路徑不穿在??
????????????{??
????????????????mkdir("new_bigo");//創建路徑??
????????????}??
????????????$url="upload/".$_SESSION["userid"]."/";//記錄路徑??
????????????if?(file_exists($url.$_FILES["file"]["name"]))//文件存在??
????????????{??
????????????????echo?$_FILES["file"]["name"]?.?"?already?exists.?";??
????????????}??
????????????else//文件不存在??
????????????{??
????????????????$url=$url.$_FILES["file"]["name"];??
$new_url?=?"D:\phpStudy\WWW\bingo\img\123.jpg";
????????????????move_uploaded_file("new_bigo",$url);??
????????????????echo?"Stored?in:?"?.?$url;??
????????????}??
????????}??
?????}??
????else??
????{??
????????echo?"Invalid?file";??
????}??
?>??
??
<html>??
<body>??
????<br><br>??
????<img?src="<?php?echo?$url;?>">??
</body>??
</html>??
</body>
</html>結果:從文件大小之后好像都錯了,但是不知道錯在那里
php 新手求教 file問題
慕村1106498
2017-06-16 22:52:30