Access a file through server path - php

Setup:
The server path of the website is located at /var/www/website/. Here I have index.php file that's using jPlayer (audio player plugin) to play MP3s.
Issue:
I need to access the MP3 files from /gdrive/MP3s/ (server path). E.g. /gdrive/MP3s/sample.mp3
On the code (index.php), I tried putting the MP3 path /gdrive/MP3s/sample.mp3 on jPlayer but it didn't work (it's treating the path as http://website.com/gdrive/MP3s/sample.mp3).
Then I tried ../../../gdrive/MP3s/sample.mp3. I thought it will do the trick but also, it didn't work.
Question:
How can I access the MP3 files based from above?
Last resort would be to create virtualhost for /gdrive/MP3s/ but I want to avoid that if possible.

(assuming you're using a linux machine)
Create a symbolic link from your MP3 folder to a web-accessible location.
ln -s /gdrive/MP3s/ /var/www/website/MP3s
Then you can access that folder at http://yoursite.com/MP3s/bleh.mp3 and access the files through jplayer at /MP3s/bleh.mp3
Think of it like a shortcut link

Related

displaying pdf files located in temp folder using IFrame

Well, I got an API which read binary file from database and store it as "PDF" in windows temp folder, then it sends the path to that file to "PHP" page. What I want is to display that file over the browser.
The API returns the PDF file path: C:\Users\username\APPDATA\Local\Temp\some file.pdf. What I have done is setting that path to an iframe in my page,
but it shows nothing.
What am I missing here?
You should convert that local path to an url one.
Http://www.yourpage.com/folder_where_you_keep_those_files/file.pdf
And give the proper folder and file permissions.
The PDF is on YOUR computer, the user cannot access YOUR C:\ drive.
You cannot exchange your client-side files with someone server-side.
Store your PDF file on the server somewhere and set that path in the iframe.
You need to move that file from you local path (it can be your tmp folder or another folder that is not in your web accessible path) to your web directory so that you can put that in your iframe source.
Eg:
<iframe src="http://yourwebsite.com/somepdf.pdf" width="1000px" height="800px" >

Is it possible for someone to get a list of all the files in Apache's www folder without FTP?

I have a 2.5GB file that I want to allow users to download after they buy it. I originally planned on hiding the file and then just using readfile to dump the file's contents with .zip headers but my GoDaddy server apparently won't allow me to use readfile on such a large file, so I'm stuck with changing the name of this important file every hour. But if someone can just list all the files on my www folder anyway then people can take it without paying for it.
Any suggestions?
As long as you don't allow indexing of the directory then they can't obtain a file listing. To do that create a .htaccess file in the directory and add:
Options -Indexes
Alternatively, if the folder has an index page this will also prevent the server disclosing a directory listing and instead serve the index page.
if you have more than 5 gig host so use the php exec command to copy your file with another name
let say you keep your file with a unguessable name in a unguessable folder
so whenever the buyer confirm the order then you copy the file to a known folder with user-generated name, then pass the link to user
if your host is linux then use cp command if it's windows use copy
use something like cp oldname.ext newname.ext or copy oldname.ext newname.ext
after a certain time you will delete the file in the known folder

Download files above web root and list them

I am trying make a php script to list the files of a folder above my web directory...I follow a small thing I found here which talked about
a symlink pointing to /var/uploads
a Apache Alias directive Alias /uploads /var/uploads
I did both of these.
$myDirectory = opendir("/var/stuff/stuff/");
That directory there links to like when I go in winscp and click that folder it directs me to it....and when I run my script to list all files inside /var/stuff/stuff/ it lists what is in /home/stuff/stuff.
The thing is when I click the links that it produces I get a not found on the server
The requested URL /stuff was not found on this server.
Would someone please be able to assist me with this?
Since the files are not under the root directory, you will not be able to download them directly, but What you can use for this issue is to create a downloader gateway.
I'll explain:
create a php script somewhere in your app, lets call it downloader.php
the downloader script would get a parameter, lets say: filename
now we could call the script like: http://YOUR-URL/downloder.php?filename=file-to-download
in your downloader.php file you can get the file name, read it from the file system, then force it to be downloaded by out puting its content and configure the correct headers
I'm not sure if you still need that but, if you need more assistance I can help you more with some code samples
ideally you can use .htaccess to hide your downloader gateway script

PHP Download file from non-hosted directory

I've been able to upload a file through PHP to a non-hosted directory (directory is not on the website) with read/write permissions for the PHP file (www). How would I download the file from this directory? I've been able to list the contents of the directory, but clicking on the files (made the filenames links) does not work as the computer attempts to download the file from the path on the server. I'm new to PHP, so all help is appreciated. Thanks!
Edit: Before I get down votes for this being a broad question, I just want to know how to access the files in the non-hosted directory and pass them to the user. I already know how to download normal files hosted on the website. Thanks!
You can use a delegating PHP file for file access. I don't know anything about your structure, but if you can write it, you can (presumably) read it back with file_get_contents:
<?php
echo file_get_contents('/the/path/to/the/unhosted/directory/file.ext');
?>

List all names of files in a Web directory (uploads) using protocol HTTP

I'm trying to list all files (. DOC and. PDF) contained in a specific Web directory.
The problem is that I do not have access. I can only download with the full path of the file.
Example:
Directory 1: http://xxx.example.com/uploads/local20/40
Files:
45677.pdf
54354.doc
65767.doc
54354.pdf
43243.pdf
...
Directory 2: http://xxx.example.com/uploads/local20/41
Files:
45453.pdf
67566.pdf
89798.pdf
89898.doc
52254.pdf
...
I can manually download the files of directory 40 and 41, because I know your path, then
write:
http://xxx.example.com/uploads/local20/40/65767.doc (Download -> OK)
But how to download all the files contained in this directory without knowing the names of files? Or at least list the names of all files.
Obs 1: When I type only the directory (without the name of the file) it returns me an error in XML format. Ex: http://xxx.example.com/uploads/local20/40/
Response: XML Error
...
NoSuchKey
...
Obs2: The Web application use the PHP language.
In order to have the files in a folder listed out in html format when you browse to that folder with a web browser, you'll have to turn on directory browsing in your Apache configuration and make sure you don't have a default page (eg. index.php) in that folder. Don't forget to restart Apache after making the change.
BTW: If this is a folder where files can be uploaded, it really shouldn't be directly publicly accesible because you'll have a pretty major security vulnerability on your hands. Someone can upload a malicious PHP script and then run it by simply hitting the URL in a browser.

Categories