This topic is locked

Hyperlink file download

4/17/2009 3:38:28 PM
PHPRunner General questions
D
drbyte2009 author

Hello all,
I have a list page, on that page there is a title field, the tittle field is linked to a

file on my server. (this relation also exists in the database table)

I don't show the linked column on my list page.
How can a make a hyperlink that downloads the linked file.

The file's are always in the same directory.
For example:
Title

Whats in a name
Title_id

123456.doc
I need to download the 123456.doc file.

I have been searching for a solution on the form for one day now...., can someone help me with this.
Thanks in advance!

A
alang 4/17/2009

On the visual editor page, double click the field and select hyperlink for "view as" type. You can then set the URL prefix as "file://..." for whatever your base path is.

D
drbyte2009 author 4/18/2009

On the visual editor page, double click the field and select hyperlink for "view as" type. You can then set the URL prefix as "file://..." for whatever your base path is.


Ok, seems a nice and smart solution, but how do i pass the variable (a number from the same table) to this link to get the right file ??

Sergey Kornilov admin 4/18/2009

You can use 'View as' type 'Custom' and access any field via $data["FieldName"].
Example:

global $data;

echo $data["FieldName"];
D
drbyte2009 author 4/19/2009

You can use 'View as' type 'Custom' and access any field via $data["FieldName"].

Example:

global $data;

echo $data["FieldName"];


Ok, that's clear, but i need to know how to download this file

See my first question please.
Thanks in advance!

J
Jane 4/20/2009

Hi,
here is just a sample:

$value = "<a href=\"folder/".$data["FieldName"]."\" >Link</a>;



where folderis your actual name of directory where your files are stored.

D
drbyte2009 author 4/20/2009

Hi,

here is just a sample:
where folderis your actual name of directory where your files are stored.


Hi Jane,
I used your code (copy / paste) but, then i get the following error
Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE or '$' in /var/www/test/include/commonfunctions.php on line 562
Please help...

J
Jane 4/20/2009

Sorry for my fault.

Here is the correct:

$value = "<a href=\"folder/".$data["FieldName"]."\" >Link</a>";

D
drbyte2009 author 4/20/2009

Sorry for my fault.

Here is the correct:


Thanks this works !!, only where can i place the extension of the file, now i get only the filename without the extension.

The extension is always the same.
Thanks a lot !!

D
drbyte2009 author 4/20/2009



Thanks this works !!, only where can i place the extension of the file, now i get only the filename without the extension.

The extension is always the same.
Thanks a lot !!


I just played a little bit with the code. The code below works, but shows the file instead of downloading it.

I want to download the file, is this possible?
$value = "<a href=\"doc/".$data["filename"].".txt\">".$data["title"]."</a>";
Thanks in Advance!

Sergey Kornilov admin 4/20/2009

Try the following:

$value = "<a href=\"doc/".$data["filename"].".txt\">".$data["filename"]."</a>";
D
drbyte2009 author 4/20/2009

Try the following:


$value = "<a href=\"doc/".$data["filename"].".txt\">".$data["filename"]."</a>";


The code above is not what i need, i tried it, but it also opens the file instead of downloading.

The code below is correct for me, it displays the right things

$data["title"] = the name to show to the users

$data["filename"] = the filename linked to the title
$value = "<a href=\"doc/".$data["filename"].".txt\">".$data["title"]."</a>";

Sergey Kornilov admin 4/20/2009

I see what you saying.
You can right-click on this link and choose 'Save link as'.

D
drbyte2009 author 4/21/2009

I see what you saying.

You can right-click on this link and choose 'Save link as'.


Is there really no solution that you only need to click on the hyperlink, and then the download starts?
Thanks.

Sergey Kornilov admin 4/21/2009

It depends on your browser. Some browsers will open text files right in the browser while others will offer to download the file. This is a browser thing and you cannot control it from the web page.

D
drbyte2009 author 4/21/2009

It depends on your browser. Some browsers will open text files right in the browser while others will offer to download the file. This is a browser thing and you cannot control it from the web page.


Ok, i'am using firefox as browser, let's see what internet explorer does.
Thanks for the answers!