PHP 只接受一种扩展类型上传。该文件是未知的扩展类型
PHP Accepting only one extension type to upload. The file is an unknown extension type
这是我的第一个问题。我是 PHP 的新手,但我一直在寻找这个问题的答案大约一个小时,但一直没有成功。也许我只是没有正确阅读它,但我希望你们能帮助我。
我试图让人们只将一种文件类型上传到我的网站。该文件类型是 .osk 。我不确定我这样做是否正确,但我是这样设置的
$types = array ('application/osk');
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$target_path = "skins/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path, $types)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
每当我提交该特定文件类型时,我都会收到错误消息。如果我提交任何其他内容,我也会收到错误消息,但这是预料之中的。
对不起,如果代码是一团糟。正如我之前所说,我对此很陌生。但是,如果有人可以帮助我解决这个问题,我会很高兴。
试试这个代码
$file_parts = pathinfo($_FILES['uploadedfile']['name']);
// Check file is osk
if($file_parts['extension'] == 'osk')
{
// move file
if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path))
{
echo "Uploaded";
}
else
{
echo "File was not uploaded";
}
}
这是我的第一个问题。我是 PHP 的新手,但我一直在寻找这个问题的答案大约一个小时,但一直没有成功。也许我只是没有正确阅读它,但我希望你们能帮助我。 我试图让人们只将一种文件类型上传到我的网站。该文件类型是 .osk 。我不确定我这样做是否正确,但我是这样设置的
$types = array ('application/osk');
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$target_path = "skins/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path, $types)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
每当我提交该特定文件类型时,我都会收到错误消息。如果我提交任何其他内容,我也会收到错误消息,但这是预料之中的。 对不起,如果代码是一团糟。正如我之前所说,我对此很陌生。但是,如果有人可以帮助我解决这个问题,我会很高兴。
试试这个代码
$file_parts = pathinfo($_FILES['uploadedfile']['name']);
// Check file is osk
if($file_parts['extension'] == 'osk')
{
// move file
if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path))
{
echo "Uploaded";
}
else
{
echo "File was not uploaded";
}
}