-2
嘿傢伙我想在我的網站上創建一個文件上傳器,並且我遵循了一個教程,但它似乎不起作用。我目前使用下面的代碼:PHP文件上傳
<?php
session_start();
include('../../config/config.php');
if(isset($_SESSION['id'])) {
$filename = $_FILES["file"]["name"];
$filesize = $_FILES["file"]["size"];
$name = $_POST['name'];
$price = "$" . $_POST['price'];
$photo = $_POST['file'];
$description = nl2br($_POST['description']);
$file_ext = getExt($photo);
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 />";
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 {
header("Location: ../../index.php");
}
?>
我似乎創建臨時文件很好,但我不知道爲什麼我不會移動它。現在我正在用圖像文件測試代碼。
而且,這裏是我的表單代碼:
<form method="post" action="actions/add.php" enctype="multipart/form-data">
</br>
Listing name: <input type="text" name="name" /></br></br>
Listing Photo: <input type="file" name="file"/></br></br>
Price: $<input type="text" name="price"/></br></br>
Information:</br>
<textarea class="add" name="description"></textarea>
</br></br>
<input class="add" type="submit" name="submit"/>
</form>
編輯:
一些錯誤:
Warning: move_uploaded_file(upload/Corgi 004.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/stationr/public_html/admin/actions/add.php on line 42
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/chroot/tmp/phpLXObbt' to 'upload/Corgi 004.jpg' in /home/stationr/public_html/admin/actions/add.php on line 42
感謝您的幫助。
在上傳文件和PHP幫助的過程中,對本網站上的任何其他問題做過嗎?看到右側的所有鏈接? – 2011-12-31 06:36:01
http://nz.php.net/manual/en/features.file-upload.php – zerkms 2011-12-31 06:37:40
啓用錯誤報告,檢查目錄權限等過於本地化。 – mario 2011-12-31 06:45:04