JaxPHP / JaxWeb Message Board › MYSQL Results

MYSQL Results

A former member
Post #: 11
HI Guys & Gals

Sorry for the double post didn't know if anyone ever checked the other board and I goofed when I posted there. OOOPPPSSS!!!

I am working on a project and need a little help. I have a form that input a PDF file to a directory and record where that file is place in DB all works fine.
Problem is when I query DB I get results that look like this

/var/www/html/gene0/site/workdocs/3660­047invpod.pdf
and here is how I get these results

while ($row = @mysql_fetch_array($query3)) {
$doc_id = $row['doc_id'];
$document = $row['document'];
echo "
<tr>
<td>$doc_id</td>
<td>$document </td>
</tr>";

When what I am really trying to do is get a link where client can click on and get documentname.pdf

thanks
Gene
A former member
Post #: 11
Hey Gene,

The simplest solution is to also store a relative path to the file when it is created.

From the path you gave I would assume the file can be found at a URL similar to this:

http://www.yoursite.c...­
or
http://www.yoursite.c...­

depending on how your server is setup.
A former member
Post #: 11
If your files is somewhere not accessible to a browser you're other option is to have PHP send the appropriate HTTP headers for a file download and then dump out the contents of the file to the browser. Basically, simulating what Apache (or some other web server) does.

Check out the example in this PHP function's docs: http://php.net/manual...­

In reality you need to worry more about MIME types, but the above link will get you started.

So you can create a separate PHP page (using the code mentioned above) that you pass the file name to as a $_GET variable. Then, you link to that separate script in your HTML. The download script will look up the file on the server and then send it to the browser and the user is none the wiser that any craftiness is going on.
A former member
Post #: 12
Hey thanks for the reply guys, I posted this after one of those 20+ hour crunches. So i may have confused everyone I have to take the file and create links on a HTML doc so the end user can just click on the link and down load the pdf. So the flow will be client upload pdf via web page "not ftp" then his end user will visit a web page with a list of pdf files and they click on the one they choose.

Thanks agian
Gene
A former member
Post #: 103
I have to take the file and create links on a HTML doc so the end user can just click on the link and down load the pdf. So the flow will be client upload pdf via web page "not ftp" then his end user will visit a web page with a list of pdf files and they click on the one they choose.

Okay let see if I have this:
Upload file -- OK
INSERT DB -- OK
SELECT DB -- bad file path ?

It looks like you do have a fixed file path of /workdocs/. If this is so then in the DB just store the PDF file name. if not, store in another column the folder name and replace workdocs below with $workdocsname. (like ben said use relative path).

while ($row = @mysql_fetch_array($query3)) {
$doc_id = $row['doc_id'];
$document = $row['document'];
echo "
<tr>
<td>$doc_id</td>

// I bracketed the last slash in the html due to it is making them a real link http:/(/)www.yoursite.com


<td> <a href=\"http:/(/)www.yoursite.com/wo­rkdocs/$document\" title=\"$doc_id\">$document­</a></td>

or relative with base ref in HTML head which should be there already but can throw off improperly written links, so might be best to longhand it as above in blue then below in red.

<?php
if($_SERVER['HTTPS']){
echo "<base href=\"https:/(/)www.yoursite.com/\­" />";
}else{
echo "<base href=\"http:/(/)www.yoursite.com/\"­ />";
}
?>

<td> <a href=\"/workdocs/$document\" title=\"$doc_id\">$document­</a></td>

</tr>";

To force download of the PDF rather than view (view allows download though) you would need to do as Donald said which is really simple to do How To Use PHP to Force a File Download Though best to use Donald's link as I try to start with php.net for php answers first.

Tim
A former member
Post #: 104
Gene, hope one of us provided some help. Since everyone has various skills and skill levels in programming and I do not know if I was understanding completely. I did ignore the input side before it goes to the database so here is a rough idea of inserting just the filename.

$somepdf = "some.pdf";
$thedirectory = "/workdocs."/";

$uploaddir = $_SERVER['DOCUMENT_ROOT'].$thedirectory;­
$uploadfile = $uploaddir.$somepdf;

if (move_uploaded_file($thefile['tmp_name']­, $uploadfile)) {
chmod($uploadfile , 0755); // or what ever permission level best like 644
}

So I would insert $somepdf in the database rather than $uploadfile and handle the directory structure in the php coding.
A former member
Post #: 13
Hey thanks everyone for the help and the quick responses. Tim your href tag is what I was missing something so simple sometimes.

Thanks Again
Gene Crain
Eric N.
user 4016762
Group Organizer
Orange Park, FL
Post #: 72
A late entry, and just a suggestion...

I've done a lot of this in the past, and I prefer to upload files like this to a directory outside the web tree, for security. Then you can retrieve them with a php script that presents the appropriate header for the file type.

I can post links to examples if anyone's still interested.
Powered by mvnForum

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy