...

View Full Version : Making output in to a hyperlink



DJ Hands3
03-02-2009, 07:45 PM
Hello I have a .php page that will display a link to download a file but it only appears as text rather that a hyper link, it may be simple to do but my .php skills are very basic the code is below

The particular bit of the code i need to modify is this below, i dont know but maybe changing print to echo?


if ($dbim->num_rows($mirrors_result) == 1)
{
$error_message = $lm->language('frontend', 'error_no_file');
$error = $uim->fetch_template('global/error');
$error->assign_var('error_message', $error_message);

// Go
print(http://dj-promo.co.uk/cgi-bin/play.m3u?advert=simplygarage.mp3&show='.$mirror['url']);
$error->show();



The full .php page is below




<?php
/**********************************
* Olate Download 3.4.1
* http://www.olate.co.uk/od3
**********************************
* Copyright Olate Ltd 2005
*
* @author $Author: dsalisbury $ (Olate Ltd)
* @version $Revision: 259 $
* @package od
*
* Updated: $Date: 2006-10-10 20:27:12 +0100 (Tue, 10 Oct 2006) $
*/

// Initialisation
require('./includes/init.php');

// Show categories
$fcm->show_cats();

// Start sessions
session_start();

// 1. Check isset($input'file']) then get details
if (isset($input['file']))
{
validate_types($input, array('file' => 'INT', 'go' => 'INT', 'mirror' => 'INT'));

// Get file details
$details = $fldm->get_details($input['file']);

if (empty($details['password']) || isset($_SESSION[$input['file'].'_auth']))
{
// 2. If page called !isset($input['go']) and there is an agreement, display
if (!isset($input['go']) && $details['id'] != 0 && !empty($details['agreement_id']))
{
// Get the agreement
$agreement = $fldm->get_agreement($details['agreement_id']);
$agreement_template = $uim->fetch_template('files/agreement');
$agreement_template->assign_vars(array('agreement' => $agreement,
'file_id' => $details['id']));


$agreement_template->show();
}
// 3. If !isset($input['go']) || $input['go'] == 1 check !empty($details) and get mirror data
elseif (!isset($input['go']) || $input['go'] == 1)
{
if (!empty($details))
{
// Get mirrors
$mirrors_result = $dbim->query('SELECT id, file_id, name, location, url
FROM '.DB_PREFIX.'mirrors
WHERE (file_id = '.$input['file'].')');

// 4. If $dbim->num_rows($mirrors_result) == 1 redirect to get it
if ($dbim->num_rows($mirrors_result) == 1)
{
$mirror = $dbim->fetch_array($mirrors_result);
header('Location: download.php?go=2&file='.$input['file'].'&mirror='.$mirror['id']);
}
// 5. If $dbim->num_rows($mirrors_result) > 1 get and display list
elseif ($dbim->num_rows($mirrors_result) > 1)
{
// Fetch and display
$mirrors_template = $uim->fetch_template('files/mirrors');

while ($mirror = $dbim->fetch_array($mirrors_result))
{
$mirrors_template->assign_var('file_id', $input['file']);
$mirrors_template->assign_var('mirror', $mirror);
$mirrors_template->use_block('mirror');
}

$mirrors_template->show();
}
else
{
$error_message = $lm->language('frontend', 'error_no_file');
$error = $uim->fetch_template('global/error');
$error->assign_var('error_message', $error_message);
$error->show();
}
}
else
{
$error_message = $lm->language('frontend', 'error_no_id');
$error = $uim->fetch_template('global/error');
$error->assign_var('error_message', $error_message);
$error->show();
}
}
// 6. If $input['go'] == 2 and isset($input['mirror']), validate id, increment download count then redirect to URL
elseif ($input['go'] == 2 && isset($input['mirror']))
{
// Get referring domain
if (empty($_SERVER['HTTP_REFERER']))
{
$referer_domain = false;
}
else
{
$referer = parse_url($_SERVER['HTTP_REFERER']);
$referer_domain = $referer['host'];
}

if (($referer_domain !== false && !$sm->domain_can_leech($referer_domain) && empty($_SESSION['valid_user'])) || ($site_config['enable_leech_protection']

== 1 && empty($_SESSION['valid_user'])))
{
header('Location: details.php?file='.$input['file']);
exit;
}

// Incrememnt and update
$details['downloads']++;
$update = $dbim->query('UPDATE '.DB_PREFIX.'files
SET downloads = '.$details['downloads'].'
WHERE (id = '.$input['file'].')');

if ($site_config['enable_stats'])
{
$dbim->query('INSERT INTO '.DB_PREFIX.'stats
SET file_id = '.$input['file'].',
timestamp = "'.time().'",
ip = "'.$_SERVER['REMOTE_ADDR'].'",
referrer = "'.$_SERVER['HTTP_REFERRER'].'",
user_agent = "'.$_SERVER['HTTP_USER_AGENT'].'"');
}

// Get URL
$mirrors_result = $dbim->query('SELECT id, url
FROM '.DB_PREFIX.'mirrors
WHERE (id = '.$input['mirror'].')');

$mirror = $dbim->fetch_array($mirrors_result);

if ($dbim->num_rows($mirrors_result) == 1)
{
$error_message = $lm->language('frontend', 'error_no_file');
$error = $uim->fetch_template('global/error');
$error->assign_var('error_message', $error_message);

// Go
print('http://dj-promo.co.uk/cgi-bin/play.m3u?advert=simplygarage.mp3&show='.$mirror['url']);
$error->show();


}
}
}
else
{
// Get template
$protection = $uim->fetch_template('files/protected');
$protection->assign_var('file_id', $input['file']);

// Show template
$protection->show();
}
}
else
{
$error_message = $lm->language('frontend', 'error_no_id');
$error = $uim->fetch_template('global/error');
$error->assign_var('error_message', $error_message);
$error->show();
}

// End table
$end = $uim->fetch_template('global/end');
$end->show();

// Show everything
$uim->generate(TITLE_PREFIX.$lm->language('frontend', 'download').' '.$details['name']);
?>

eu4ria
03-02-2009, 08:08 PM
Change


// Go
print(http://dj-promo.co.uk/cgi-bin/play.m3u?advert=simplygarage.mp3&show='.$mirror['url']);



to something like:


// Go
print('<a href=http://dj-promo.co.uk/cgi-bin/play.m3u?advert=simplygarage.mp3&show='.$mirror['url'] . '>Click here</a>');

DJ Hands3
03-02-2009, 10:27 PM
Thanks eu4ria for that, I'v come stuck again to finish what i need to do i need to place the link in a pop up window i'v had a go but get loads of errors im trying this at the moment:



$error_message = $lm->language('frontend', 'error_no_file');
$error = $uim->fetch_template('global/choosedownload');
$error->assign_var('error_message', $error_message);

// Go
print('<div class=box><h1 style=margin:0>Mix options - stream or download this file</h1><h3><p style=border:0><a href=http://dj-promo.co.uk/mixes/downloadpromo.htm?filename1='.$mirror['url'] . ' onclick="return !window.open(this.href,'','scrollbars=0,height=50,width=50');"> Stream this mix<img border=0 src=images/files/icon_winamp.png width=18 height=18></a></br><a href=http://dj-promo.co.uk/cgi-bin/play.m3u?advert=simplygarage.mp3&show='.$mirror['url'] . '>Download this mix<img border=0 src=images/files/icon_winamp.png width=18 height=18></a></p></h3></div>');


$error->show();




<a href=http://dj-promo.co.uk/mixes/downloadpromo.htm?filename1='.$mirror['url'] . ' onclick="return !window.open(this.href,'','scrollbars=0,height=50,width=50');"> Stream this mix<a>


but says Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING

i tried a few ways but cant get it to work, i know theres away of writing it properly but not sure how to.

The pop up parameters I will change as at the moment theres no point calling the page its set to in a pop up, but once i have changed the pop up will show a flyer for an event before the download.php calls the file to download.

sea4me
03-03-2009, 12:00 AM
Try:



// Go
print("<div class=box><h1 style=margin:0>Mix options - stream or download this file</h1><h3><p style=border:0><a href=http://dj-promo.co.uk/mixes/downloadpromo.htm?filename1=".$mirror['url']." onclick=\"return !window.open(this.href,'','scrollbars=0,height=50,width=50');\"> Stream this mix<img border=0 src=images/files/icon_winamp.png width=18 height=18></a></br><a href=http://dj-promo.co.uk/cgi-bin/play.m3u?advert=simplygarage.mp3&show=".$mirror['url'].">Download this mix<img border=0 src=images/files/icon_winamp.png width=18 height=18></a></p></h3></div>");

DJ Hands3
03-04-2009, 08:22 PM
Thanks or all the help so far its going good, iv now stumbled on 1 thing i would like to do, on this line of code below:



// Go
print("<div class=box><h1 style=margin:0>Mix options - stream or download this file</h1><h3><p style=border:0><a href=http://dj-promo.co.uk/mixes/downloadpromo.htm?filename1=".$mirror['url']." onclick=\"return !window.open(this.href,'','scrollbars=0,height=50,width=50');\"> Stream this mix<img border=0 src=images/files/icon_winamp.png width=18 height=18></a></br><a href=http://dj-promo.co.uk/cgi-bin/play.m3u?advert=simplygarage.mp3&show=".$mirror['url'].">Download this mix<img border=0 src=images/files/icon_winamp.png width=18 height=18></a></p></h3></div>");


you can see advert=simplygarage.mp3 but the file name being simplygarage.mp3 i would like to generate a random mp3 file name from a folder where all the mp3's are stored, just so the file name of a random mp3 file is inserted into the query string then the cgi script can take care of the rest,

iv been thinking on javascript terms as its easier to understand but converting this into php is beyond me, on a thought i was thinking in javascript you could have the arrays or vars (i think) as the available file listed in which ever folder then the script would just generate a random order for the files, id rather keep in php as it better than javascript more stable.

If you could help all good:thumbsup:

DJ Hands3
03-05-2009, 01:19 PM
Iv had a go in php trying to merge a radom text script in but go a problem Parse error: syntax error, unexpected T_VARIABLE




$error_message = $lm->language('frontend', 'error_no_file');
$error = $uim->fetch_template('global/choosedownload');
$error->assign_var('error_message', $error_message);
$random_text = array("intro1.mp3",
"intro2.mp3",
"intro3.mp3",
"intro4.mp3",
"intro5.mp3");
srand(time());
$sizeof = count($random_text);
$random = (rand()%$sizeof);
// Go
print("<div class=box><h1 style=margin:0>Mix options - download or stream this file</h1><h3><p style=border:0><a href=http://dj-promo.co.uk/mixes/downloadpromo.htm?filename1=".$mirror['url']." onclick=\"return !window.open(this.href,'','scrollbars=0,height=50,width=50');\">Download this mix <img border=0 src=images/files/download.gif width=18 height=18></a></br><a href=http://dj-promo.co.uk/cgi-bin/play.m3u?advert="$random_text[$random]&show=.$mirror['url'].">Stream this mix <img border=0 src=images/files/winamp.gif width=18 height=18></a></p></h3></div>");




$error->show();



any advice on what i could do to make work

kokjj87
03-05-2009, 01:48 PM
Error here:

advert="$random_text[$random]&show=.$mirror['url'].">
Correct way

advert=".$random_text[$random].'&show='.$mirror['url'].">



Corrected


print("<div class=box><h1 style=margin:0>Mix options - download or stream this file</h1><h3><p style=border:0><a href=http://dj-promo.co.uk/mixes/downloadpromo.htm?filename1=".$mirror['url']." onclick=\"return !window.open(this.href,'','scrollbars=0,height=50,width=50');\">Download this mix <img border=0 src=images/files/download.gif width=18 height=18></a></br><a href=http://dj-promo.co.uk/cgi-bin/play.m3u?advert=".$random_text[$random].'&show='.$mirror['url'].">Stream this mix <img border=0 src=images/files/winamp.gif width=18 height=18></a></p></h3></div>");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum