我想了PHP我的第一個實際腳本,其中大部分來自教程:( 反正是PHP文件類型限制
我在這部分有問題
// This is our limit file type condition
if (!($uploaded_type=="text/java")||!($uploaded_type=="file/class")||!($uploaded_type=="file/jar")) {
echo "You may only upload Java files.<br>";
$ok=0;
}
它基本上不!讓任何文件,即使是那些在那裏 幫助 我想要的Java文件要只允許
編輯:! 以下是完整的代碼
<?php
$target = "upload/";
$target = $target . basename($_FILES['uploaded']['name']) ;
$uploaded = basename($_FILES['uploaded']['name']) ;
$ok=1;
//This is our size condition
if ($uploaded_size > 350000) {
echo "Your file is too large.<br>";
$ok=0;
}
// This is our limit file type condition
if (!($uploaded_type=="text/java")||!($uploaded_type=="file/class")||! ($uploaded_type=="file/jar")) {
echo "You may only upload Java files.<br>";
$ok=0;
}
echo $ok; //Here we check that $ok was not set to 0 by an error
if ($ok==0) {
echo "Sorry your file was not uploaded";
}else {
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
echo "The file ". $uploaded ." has been uploaded";
} else {
echo "Sorry, there was a problem uploading your file.";
}
}
?>
不會讓它成爲一個.java,.class,.jar在同一時間嗎? 我做的Java,所以我可能是錯的! – Hego555
編號布爾邏輯在所有語言中都是相同的。 –
@ Hego555你正在做'沒有條件,沒有條件',這意味着它不能被整個子句評估爲TRUE。只要它匹配一個,該子句的計算結果就是FALSE。如果將其更改爲「條件或條件」(刪除NOT),它會減少混淆 - 這會產生相同的效果並更具可讀性。 – DaveRandom