php - Distribute APK on webserver
Get the solution ↓↓↓I've created an app and want users to be able to download and install the app from my website on their device (phone). I used Android Studio and generated a signed APK. Now i have 2 files (app-release.apk and output.json)
I've tried some codes but most of them I got "HTTP ERROR 500" and then I tried this simple code (PHP):
$file_name = "app-release.apk";
$file_ext = "apk";
$file_path = 'my/app/folder/' . $file_name;
header("Cache-Control: public");
header("Content-description: File Transfer");
$contenttype = "application/com.android.package-install";
header("Content-Type: " . $contenttype);
header("Content-Disposition: attachment; filename=\"".$file_path."\"");
header("Content-Tranfer-Encoding: binary");
readfile($file_path);
With this I can download the APK on the device. But...
- I cannot install the app. It just say "cannot open".
- The APK name change to this in the device download folder --> my_app_folder_app-release.apk And I don't want the users to see the website structure/folders.
Oke my questions are. How can I let the user to download and install APK from the webserver /website properly. And how can I prevent that the APK name changes?
For the first problem ... "I cannot install the app" ... I cannot install the app from the browser downloads. I have to install the app from the File Manager. This is because I changed the security so I can install unknown apps from the File Manager. So this is solved
Answer
Solution:
filename
afterContent-Disposition: attachment;
is expecting the NAME of the file that you want the file to be named when it is saved not the path to the existing file.
header('Content-Disposition: attachment; filename="$file_name"');
Also if you wanted to serve APK directly from your server via a link, I suspect you you will need to add this line to your.htaccess
on apache since APK isn't a default mime. After that you can link directly to the file and allow them to download it with no additional programming.
AddType application/vnd.android.package-archive apk
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: filter_sanitize_string
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.