-2
好了,所以這是我上傳的文件如何允許在PHP腳本上傳僅編程語言擴展
$target = "cloud/";
$target = $target . basename($_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename($_FILES['uploaded']['name']). " has been uploaded";
mysql_query("INSERT INTO data (`id`,`title`,`url`,`display`) VALUES ('NULL','". basename($_FILES['uploaded']['name']). "','http://test.info/". basename($_FILES['uploaded']['name']). "','1');");
}
else {
echo "error";
}
我應該添加什麼允許像html的.PHP的.cpp,因此只有擴展腳本?
@jprofitt:我不會依賴$ _FILE ['image'] ['type'],因爲這個值是由瀏覽器發送的,攻擊者可以僞造它。 –
@AmalMurali以下是[幾個](http://stackoverflow.com/questions/12864171/only-allow-jpg-and-png-files-only?lq=1)[other](http://stackoverflow.com/questions/10070465/php-allowable-uploaded-file-extension?lq = 1)[questions](http://stackoverflow.com/questions/10456113/php-check-file-extension-in-upload-form?rq = 1),在這裏可以更好地適應這個問題。 – jprofitt
@jprofitt:他們使用exif_imagetype(僅用於圖像),OP希望檢查擴展名,如html,php等。 –