PHP - 上傳APK到自己的服務器 (PHP - upload APK to own server)


問題描述

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

(by Blastermaxhb)

參考文件

  1. PHP ‑ upload APK to own server (CC BY‑SA 2.5/3.0/4.0)

#forms #apk-expansion-files #PHP






相關問題

創建用戶註冊網頁 (Creating a User registration webpage)

如何為兩種形式使用公共輸入? (how to use common inputs for two forms?)

表單提交為空 (Form submission empty)

JS/PHP 郵件處理程序單選按鈕 (JS/PHP Mail handler radio buttons)

包含選擇框的 Laravel CREATE 和 UPDATE 表單教程/示例 (Tutorials / Samples of Laravel CREATE and UPDATE forms that include select boxes)

無法從動態創建的選擇下拉列表中檢索值 (Unable to retrieve values from dynamically created select dropdown)

如何加載從數據庫訪問的數據到 html 表單 (How To load data that are accessed from database to html form)

從 django 文件域獲取原始路徑 (Get original path from django filefield)

HTML - 前置標籤內的表單標籤 (HTML - Form Tag Inside a Pre Tag)

SendToBack 似乎在 Firemonkey 中不起作用? (SendToBack seems to not work in Firemonkey?)

如何在 Wordpress 中呈現自定義表格中的信息? (How to render information from a custom table in Wordpress?)

使用 Node.js 腳本查看表單數據 (Seeing form data with Node.js script)







留言討論