-1
我試圖將圖片上傳到一個文件夾並將路徑保存在表格中。我試圖上傳一個jpg圖像,但它顯示錯誤:PHP Image Upload
您試圖上傳的文件是不允許的。
和
未定義指數:userfile的在C:\瓦帕\ WWW \網絡\上線db_add_page.php 21.
這是我的代碼:
add_page.php
<form action="db_sql/db_add_page.php" method="post">
<input type="text" size="100" name="tittle" required />
<input type="file" name="userfile"/>
<input type="submit" value="Submit">
</form>
db_add_page.php
$tittle = $_POST['tittle'];
$allowed_filetypes = array('.jpg','.jpeg','.png','.gif');
$max_filesize = 10485760;
$upload_path = 'uploads/';
$filename = $_FILES['userfile']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if (!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
if (filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
if (!is_writable($upload_path))
die('You cannot upload to the specified directory');
if (move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
{
$acc_status = "INSERT INTO add_services (aid,tittle,name)
VALUES(NULL,'".$tittle."','".$filename."')";
db::getInstance()->exec($acc_status);
}
它可以是大寫(.JPG,.JPEG,.PNG,.GIF)..大多數相機生成的圖像都是這樣做的。 – Roi 2014-10-20 07:13:02
也將此屬性添加到窗體標記
同樣的錯誤「您嘗試上傳的文件不被允許。」 – Tje 2014-10-20 07:44:39