displaying pdf files located in temp folder using IFrame - php

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" >

Related

dynamically give pdf path in pdf.js using php mysql

I've developed a small application in php and mysql, where i'm uploading pdf and moving file to UPLOADS folder and storing path in database.
But in viewing after passing path i'm not able to open pdf on browser.
I've uploaded PDF.JS files in my folder aswel.
Below are my testing urls.
http://www.farukhzama.com/fileupload/index.php
http://www.farukhzama.com/fileupload/view.php
Your link is :
http://www.farukhzama.com/fileupload/viewer.html?file=uploads/47920-ombudsman-acknowledgement.pdf at view.php file, which is wrong path to get the pdf file.
Give it right path like this => http://www.farukhzama.com/fileupload/uploads/47920-ombudsman-acknowledgement.pdf
Thanks!

PHP redirect and rename file download

I've got the following situation: I have some files with hashed filename on a cdn. Now I want a php script which redirects to the files (download) and give them another name. Is there a way without using readfile? The problem with readfile is that it doesn't make sense to download the file from cdn to my webserver and then download the file from the webserver to local computer.

Access a file through server path

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

PhP download to root folder

If I have a php file on my root folder on my website, is there a way to go to a download line with that file and download the file to the directory where the php is rather than to the computer>
As #Cale_b said, no, not without FTP. The PHP file will execute if you try and get it through the browser. Why do you want to do that anyway?

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');
?>

Categories