作者dream1129 ( 人各有志)
看板PHP
標題[請益] 上傳檔案的問題
時間Sun Mar 12 01:21:22 2006
我是採用從系統default的暫存資料夾將檔案搬移過來,
使用 move_uploaded_file()。
但是出了一些小問題,我看不出來,請大家幫幫我 >"< ~~
程式碼:
我的位置:127.0.0.1\practice\uploading.php
<?php
$upfile="\practice\images\".$_FILES['userfile']['name'];
if(is_uploaded_file($_FILES['userfile']['tmp_name']))
{
if(!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile))
{
echo "Error";
}
}
?>
上傳檔案時,會出現這樣的錯誤:
Warning: move_uploaded_file(\practice\images\123.jpg)
[function.move-uploaded-file]: failed to open stream:
No such file or directory in C:\AppServ\www\practice\uploading.php
on line 13
Warning: move_uploaded_file() [function.move-uploaded-file]:
Unable to move 'C:\WINDOWS\TEMP\php8D.tmp' to
'\practice\mages\123.jpg'
in C:\AppServ\www\practice\uploading.php on line 13
我改成絕對路徑:
$upfile="C:\AppServ\www\practice\images\".$_FILES['userfile']['name'];
會產生這樣的錯誤:
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in
C:\AppServ\www\practice\uploading.php on line 9
後來不小心把路徑最後一個反斜線沒打到,如下
$upfile="C:\AppServ\www\practice\images".$_FILES['userfile']['name'];
檔案上傳成功了,只是是在practice資料夾下,檔名:images123.jpg
後來發現,只要打
$upfile="C:\AppServ\www\practice\images\xxx".$_FILES['userfile']['name'];
就可以將檔案搬移到images下,檔名:xxx123.jpg
我一直用不好,大家幫幫我~~>"<
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.167.57.43
1F:推 FancyWing:我猜\images\".$_FILES['u~ => \images\\".$_FILES['u~ 03/12 10:16
2F:→ FancyWing:應該是 \" 送出的是 " 導致前面字串少一個" 以致出錯 03/12 10:17
3F:→ FancyWing:不曉得您用哪套編輯器 有區別顏色的應該能一眼明瞭 03/12 10:18
4F:→ FancyWing:變數的顏色不對 03/12 10:19
5F:推 dream1129:ㄟ!!真的耶~~太感謝了!!我搞好久說>"< 03/12 12:32
6F:→ dream1129:我剛學PHP,所以還只會用筆記本寫~~ 03/12 12:33
7F:→ dream1129:可不可推薦我ㄧ些好用的編輯器 03/12 12:33
8F:推 ottokang:的活動有大家推薦的編輯器 03/12 12:41
9F:推 picachuxyz:這裡一樣建議用伺服器跟目錄寫法.... 03/12 14:33
10F:→ picachuxyz:$upload_dir=$_SERVER['DOCUMENT_ROOT'].'/upload/'; 03/12 14:34