hide download link of ios install app by php - php

Solved.
i have a link for install ios app that work in safari.
now i want to hide link from users .but i'am not sure how to do this.
i used onclick for link :
function install() {
if (!isMobile()) {
alert('you can download from ios devices');
return;
}
var post_link = $(this).attr("target");
url = 'install.php?name='+post_link;
window.location.href = url;
}
and in install.php :
<?php
$name = $_GET['name'];
$path = 'itms-services://?action=download-manifest&url=https://acqshop.com/manifest/category/'.$name;
$mm_type="application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
readfile($path); // outputs the content of the file
exit();
?>
but it not work. what's my wrong.
you can see an example for onclick function to download ios app in this site: ipa.othman.tv/ipa/vi2.php
but i can't understant what's the functions in installvi2.php
(please see the page source)
thanks.
thanks to #Shynggys
i changed install.php to :
<?php
$name = $_GET['name'];
$path = 'itms-services://?action=download-manifest&url=https://acqshop.com/manifest/category/'.$name;
$mm_type="application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header('Location:' .$path);
?>

Try to use absolute URL, not relative, and return 'false' from function 'install', it should look something like this:
function install() {
if (!isMobile()) {
alert('you can download from ios devices');
return;
}
var post_link = $(this).attr("target");
url = 'http://MyWebSite.kz/install.php?name='+post_link;
window.location.href = url;
return false;
}
Hope it helps

Related

Download and change extension in php

I have a site with my hiking-tours:
https://pknudsen.net/gps/gpxviewer.php?gpstur=777
The routes are shown on a Google map. Google requires filetype "xml". I want to make a download-function so the users can get the tours to their gps. It requiers "gpx" file types. The download code is:
function myFunction($navn) {
$path = $navn;
$mm_type="application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
readfile($path); // outputs the content of the file
exit();
}
if (isset($_GET['name'])) {
$navn = $_GET['name'];
myFunction($navn);
}
How do i change the extension to "gpx"? I don't want to write the gpx-file on my server. Just to the user.

PHP script for download and delete file works on desktop but fails on android

I have a script that download a pdf file and then delete it. This script create an instance of a class Document, then call the download() method of Document.
This is the code:
public function download($data = null){
if (file_exists($_SESSION['__config__']'html_root']."/".$this->getFilePath().$this->file)){
$this->downloadFile();
$this->deleteFile();
}
else {
$_SESSION['no_file']['file'] = $_SESSION['__config__']['html_root']."/".$this->getFilePath().$this->file;
header("Location: no_file.php");
}
}
public function downloadFile(){
$mime = MimeType::getMimeContentType($this->file);
$fp = "../../".$this->getFilePath().$this->file;
header("Content-Type: ".$mime['ctype']);
header("Content-Disposition: attachment; filename=".$this->file);
header("Content-Transfer-Encoding: Binary");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
readfile($fp);
//exit;
}
public function deleteFile(){
if (file_exists("../../".$this->getFilePath().$this->file)){
unlink("../../".$this->getFilePath().$this->file);
}
}
When I download the file on Android I get a corrupted PDF file, containing the no_file.php html code.
Without $this->deleteFile() I get the correct pdf file on Android, also.

How to upload the image into folder

I need to push the image into a folder, here image will generated in for loop according to my query, for each and every loop in need push the $img to a specific folder.
If it's possible..? Kindly give some solution.
<?php
for($i=0;$i<10;$i++)
{
$sql_sub = select_query("select DESPHOT from photo where photoid = ".$i."");
$img = $sql_sub[0][0]->load();
header("Content-type: image/pjpeg");
echo $img;
}
?>
You needs to use file_put_contents function for it.
Try
<?php
for($i=0;$i<10;$i++)
{
$sql_sub = select_query("select DESPHOT from photo where photoid = ".$i."");
$img = $sql_sub[0][0]->load();
$target_folder = 'test';
$filename = $i.'.jpg';
$new_saved = file_put_contents($target_folder.'/'.$filename, $img);
echo "Picture save as ".$new_saved;
}
?>
Note You have to set 0777 permission to target_folder if you are using UNIX/LINUX.
Above code is not tested. What $sql_sub[0][0]->load(); do?
Your going to need move_uploaded_file($tmp_path, $newpath)
more info here: http://php.net/manual/en/function.move-uploaded-file.php
// set headers
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $file_type");
header("Content-Disposition: attachment; filename=\"$file_name\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $file_size);

URL Redirect Masking in PHP

I have to show a download link on my site linking it to a file hosted on another domain. I am using the following approach.
1) Pick up the actual URL from the database
$fileDownloadLink = "http://whatever.com/thefile.docx";
2) Encode the url and pass it as parameter to download.php
$shortUrl = base64_encode($fileDownloadLink);
Download Please
3) Download.php decodes the passed string and try reading the file.
<?php
$str = $_GET["session"];
$path = base64_decode($str);
$mm_type="application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: " . $mm_type);
header("Content-Length: " .(string)(filesize($path)) );
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
readfile($path);
exit();
?>
But I am getting this error from download.php
Not Acceptable!
An appropriate representation of the requested resource could not be
found on this server. This error was generated by Mod_Security.
Please help.
You may just redirect in download.php;
$str = #$_GET["session"];
$path = base64_decode($shortUrl );
header("Location: $path");
exit();

Masking download link from another server which contains authentication value to the server

I'm trying to mask a download link that contains a domain of other server and some authentication value. Problem is whenever the load the download.php page, it will download an unknown file with all the authentication value in the unknown file name. Any idea how to solve this issue?
Below are the authentication code and link to the server.
$sharedSecret = "xxxxxxxxxxxxxxxxxxxxxx";
$transactionId = "test001";
$resourceId = "urn:uuid:xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxx";
$linkURL = "http://acs4.editionguard.com/fulfillment/URLLink.acsm";
$orderSource = "xxxxxx#example.com";
// Create download URL
$URL = "action=enterorder&ordersource=".urlencode($orderSource)."&orderid=".urlencode($transactionId)."&resid=".urlencode("$resourceId")."&dateval=".urlencode($dateval)."&gblver=4";
// Digitally sign the request
$URL = $linkURL."?".$URL."&auth=".hash_hmac("sha1", $URL, base64_decode($sharedSecret));
And below is the php code that I use to generate the download.
<?php
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: application/force-download; name=\"". $URL ."\"");
header("Content-Length: " .(string)(filesize($URL)) );
header('Content-Disposition: attachment; filename="'.basename($URL).'"');
readfile($URL);
?>

Categories