問題描述
PHP ‑ 上傳APK到自己的服務器 (PHP ‑ upload APK to own server)
我正在嘗試使用以下代碼將 APK 文件上傳到我自己的服務器。它有時可以與某些 apk 文件正常工作,但我無法上傳某些 apk 文件,例如我可以上傳一個名為“test”且大小為 1.5 mb 的文件,但另一個文件名為“test2”且大小為 3.5 的文件無法上傳.
PHP :
function updateAPK($id){
$name = $id.".apk";
$temp = $_FILES["application"]["tmp_name"];
$extension = array("application/octet‑stream","application/vnd.android.package‑archive");
$DIR = __DIR__."\\..\\android\\{$id}\\";
// apk format validation
if(in_array($_FILES["application"]["type"],$extension )){
//create directory if not exist
if(!dirExist($DIR)){
createDir($DIR);
}
if(move_uploaded_file($temp,$DIR."\\{$name}")){
return true;
}
}
return false;
}
HTML :
<?php
if(isset($_POST["upload"])){
updateAPK($id);
}
?>
<form method="POST" role="form" enctype="multipart/form‑data">
<div class="form‑group">
<label for="application">select APK :</label>
<input type="file" name="application" id="application" class="form‑control" required/>
<div align="center">
<button type="submit" name="upload" value="upload" class="btn btn‑default">upload</button>
</div>
</div>
</form>
參考解法
方法 1:
Your server settings are preventing uploads of big files. Please run the following script and post results:
<?php
echo "post_max: " . ini_get('post_max_size') . "<br>";
echo "upload_max_filesize: " . ini_get('upload_max_filesize') . "<br>";
echo "Trying to set values<br>";
ini_set('post_max_size','16M';)
ini_set('upload_max_filesize','16M';)
echo "post_max: " . ini_get('post_max_size','16M');
echo "upload_max_filesize: " . ini_get('upload_max_filesize');
?>
The lower of the 2 values is the upper limit of what you can upload. Eventually they can be changed using phps ini_set