Linking remote files issue - php

I am placing href links to remote files for download simple as this with ajax:
Link
but it opens in new window and cuts off http:// and returns not found error, although if i refresh the page it will start downloading the file.
Maybe i could specify the content type and pass with header somehow but i dont want to pass the file through my server, it should download it from remote link.
Hope i could explain well.
Thank you.

sounds like the remote site has some protection against hot linking.

Are you certain that the link is correct? Try testing it externally first using an online flash player such as http://www.flvplayeronline.com/ . If the video plays then as #EvilSpaceHamster stated it could be a permissions issue on the server. I noticed you stated download? Is this a requirement or do you just want to grant the user access to view the file?

Related

file url handling in PHP

Some background. I am using XAMPP on my laptop as a standalone, single-user server. I have a PHP/Ajax/JavaScript application that to all intents and purpose is a contacts and contact management system.
At the moment, web links are linked to the records as they are displayed to provide relevant content which the user selects by clicking the hyperlink. I would like to have the ability to include file links as well. So to my question:-
I have a file URL of the kind file: ///G:/home/scans/passports/tony0001.pdf which works as expected when typed into the address line of Firefox and Chrome, i.e. it fires up Adobe Reader and opens the PDF file. I use PHP to generate the relevant anchor statement using the information retrieved from the application. I give the href below:
href=file://G:/home/scans/passports/tony0001.pdf
The link does display as a URL and if I hover the cursor over the link it shows the correct File URL. If I click on the URL nothing appears to happen. I don't see any error messages.
So, my question is, is there a PHP.INI option I need to set to allow this? The functionality I am looking for is to be able to embed any sort of URL into my application and have it fire up the right handler and file.
I understand the point made regarding a potential security issue, but as I explained, I can type the file URL into the browser page and it opens as expected.
Update 16/10/15
The solution to this is to embed a windows shortcut which points to the target document in the xampp/htdocs directory (or a sub-directory). The links then work correctly using the very simple form of href=tony0001.pdf
Browsers disallow local file access such as file:// because it would be a security risk.

Can you force file download with the Dropbox API?

I'm trying to build a basic web application using the Dropbox API. I have the file upload/folder listing etc. working but cannot find in the documentation how to force the file to download to the user's browser. Is this possible?
If it is can someone point me in the right direction? I'm using the standard PHP SDK.
Dropbox.com: How do I force a file to download from the web
Force a file or folder to download
To cause the browser to download a file or folder rather than display
it, you can use dl=1 as a query parameter in your URL. For example:
https://www.dropbox.com/s/qmocfrco2t0d28o/Fluffbeast.docx?dl=1 Note
that the original share link URL may contain query string parameters
already (e.g. dl=0), so app developers should make sure to properly
parse the URL and add or modify parameters as needed.
And if that doesn't suffice you can check Wikihow: How to Force a File to Download from the Web on Dropbox, with nice screenshots.
If this is not what you had in mind you have clarified that in your question. You still can do that now.

Generate actual Youtube download link in PHP or Javascript

I have develop a media website to play video from Youtube by using jPlayer in PHP.
I have a problem with getting actual Youtube download link to make it play in my jPlayer.
Suppose that I have a Youtube link: https://www.youtube.com/watch?v=zpfNeFWA2vE and my actual download link is: http://o-o---preferred---hkg05s03---v12---nonxt5.c.youtube.com/videoplayback?upn=PnVtBEZ_KJw&sparams=cp%2Cgcr%2Cid%2Cip%2Cipbits%2Citag%2Cratebypass%2Csource%2Cupn%2Cexpire&fexp=919109%2C911646%2C920917%2C922401%2C920704%2C912806%2C913419%2C913558%2C913556%2C925109%2C912706&ms=nxu&expire=1348071130&itag=18&ipbits=8&gcr=kh&sver=3&ratebypass=yes&mt=1348046463&ip=119.15.90.10&mv=m&source=youtube&key=yt1&cp=U0hTTVBST19ISkNOM19ITFNCOmNBYVpWN2FtYXpn&id=ce97cd785580daf1&signature=74DF90D5D04F4DA2A2D588BDAFE777594673D2EE.64E845538B00C1FAA2E0AC043DAB5C512A49E45D&redirect_counter=1&cms_redirect=yes.
This actual url will expired on the next day.
Is there any method which I can paste only https://www.youtube.com/watch?v=zpfNeFWA2vE onto jPlayer or a script in either PHP or Javascript which can generate that actual link?
Note
I have download phptube from http://www.masnun.me/2011/05/17/phptube-a-php-class-to-get-download-links-from-youtube-watch-videos.html. It's working but when I download video from this generate link it said that "I don't have permission to download this file. 403 Forbidden"
Thank for helping!
Are you making sure that when you generate the youtube download links with phptube you are also accessing them from the server (and not from the client machine)? You are allowed to access these download links only from the same machine that was used to generate them (the author of phptube states that right at the beginning of the article).
A solution would be to generate these links from your server. Then use the server to download the contents to it. Then use the downloaded file to display it to the user. The problem is that your server will have to use double the bandwidth and the process will need time. YouTube just won't let you share the download links directly.
I had the exact same problem! Than I found this:
http://navarr.me/ytaudio/?q=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DtvS5MLzJfAw&s=on&psize=s&theme=dark
the source: https://github.com/navarr/ytaudio/
This script is also creating a download link like phptube. But I can acces the video from my local pc!

Protect audio file from being downloaded while still being playable through JQuery JPlayer

I have audio files saved in a folder on my server. They are called by JQuery JPlayer to be played. However if a person looks at the source of the page, they can find the location of the file and simply download it. I want to protect the files from being downloadable, but still allow JPlayer to play them. Is this possible?
I have tried denying the folder with .htaccess as well as password protecting the folder, but this prevents JPlayer from being able to play the files.
It's impossible to stop a savvy user stealing your media. But if you like, you could
use oAuth to govern access to the media resource
teach your server to only respond to media requests that contain "special" HTTP Headers, Cookies etc.
use DRM (washes mouth out)
some other URL obfuscating/expiring method you dream up..
To save time, i suggest you accept whatever you publish can be copied / taken. So, why not publish
a sample snippet (e.g. the first minute)
A lower-bitrate / mono taster version
Recently, a widget allowing you to stream Paul McCartney's new album was published in the Guardian.. how this is "secure" i don't know, I opened Chrome Dev Tools Network tab and helped myself to anything "audio/mpeg"!
I found a possible answer for you, using PHP:
Solution using PHP sessions
It's a long thread, but there's code there that will help you.
You should be aware (just in case you're not) that if someone can play the file in their browser, there is nothing to stop them playing the file and using recording software to capture the audio.

Download file using FTP and PHP

I would like to start a upload and download website for huge files (up to 1gb). I thought that it would be better to download the files using FTP (with PHP), because this protocol is especially used for these types of transfers.
The cliƫnt gets an email, including a download link to download the file (like yousendit.com). When they click on the link a download box appears. My problem is that I don't know how to show a download box using ftp and php. I have read that it isn't possible to immediately download a file by PHP, using FTP. Is this correct?
Do I have to create a temporary files on the server to let the client download the file? If yes, is this also a good solution for huge files?
What do you advice me to give the clients the possibility to download these huge files?
Thanks for your reply!
You can generate unique address based on session_id (create this folder on runtime and move huge file there) and redirect user to this link
For example, you have file huge.tgz
1. Send you client link http://***/user/john/file/huge.tgz
2. Ask user for auth in this page if they lost session
3. get session id
4. create on your server folder with name equals session id and move huge.tgz here
5. redirect user to unique ftp link ftp://***/17oe5kf8iYmpt66bjs89hcuo83/huge.tgz
You should disallow list files and directories on ftp server
Can't you send them an FTP link ? Why do you need PHP?
ftp://ftp12.freebsd.org/pub/FreeBSD/ls-lR.gz
You probably want to use PHP to handle everything but the file transfer. Once you have done all the checks you want you can redirect the browser to the file specifying the protocol as ftp. though you won't be able to have a progression bar in your site, the browser/ftp app will probably display one.

Categories