Forum Moderators: coopster

Message Too Old, No Replies

redirection @ its most basic form

         

expert_21

7:34 am on Nov 11, 2003 (gmt 0)

10+ Year Member



ok, it's quite difficult to explain my situation, but i'll try...say i've got a database containing 2 fields: ImageID & Download URL.

Is it possible for me to write a script that let the user enters the image ID (thru a form) then redirect the user to the download URL, so that the user can download the content (jpg/wav/etc.)?

The reason why i am doing this: i am using 4images, which has a table for storing image iD, download URL, etc. but I want to make it possible for users to just key in the image ID and get to download the file thru wap. Can anyone please help me? any help is appreciated. If it's possible, can please walk me through step by step, so that i can learn as i go? thanks.

dcrombie

9:50 am on Nov 11, 2003 (gmt 0)



Something like this?

<?PHP
if ($imageId) {
doQuery ("SELECT downloadURL FROM table WHERE id='$imageid'");
$downloadURL = <result of query>
Header ("Location: $downloadURL");
echo "show me the image";
exit;
} else {
# error
}
?>

expert_21

9:50 am on Nov 11, 2003 (gmt 0)

10+ Year Member



ok, i know it's hard to walk me thru everything, so i'll give it a try myself (i'm VERY new to php)


<?php
$host = "localhost";
$user = "user";
$pass = "pass";
$dbname = dbname";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$query= "select * from 4images_images where image_id='" . $_POST['image'] . "'";
$result= mysql_query($query);
// $num_results = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$filename=$row['image_media_file'];
$category=$row['cat_id'];

$file="http://...".$category."/".$filename;

header("Location:$file"); /* Redirect browser */

exit;
?>

Am i missing anything? Will this work on wap as well?

expert_21

10:04 am on Nov 11, 2003 (gmt 0)

10+ Year Member



hi thanks for the input. This works good. however, it seems to me that i can't use the form input in *.wml, can i?

expert_21

10:27 am on Nov 11, 2003 (gmt 0)

10+ Year Member



<?php

$browser = $HTTP_USER_AGENT;
$arrbrowser = array("mozilla","opera","MSIE") // put all the UA's in here
$test = "no";
$counter = 0;

while (isset($arrbrowser[$counter]))
{
if (strstr($browser,$arrbrowser[$counter])) $test = "yes";
$counter++;
}

if ($test == "yes") // then we have a browser from our array
{
echo "not allowed access";
}
else {

$host = "host";
$user = "user";
$pass = "pass";
$dbname = "db";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."<BR>");
mysql_select_db($dbname);

$query= "select * from 4images_images where image_id='" . $_POST['image'] . "'";
$result= mysql_query($query);
// $num_results = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$filename=$row['image_media_file'];
$category=$row['cat_id'];

$file="http://..."."/".$category."/".$filename;

header("Location:$file"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>
}

it says parse error on line 5...anybody?

coopster

3:41 pm on Nov 11, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Syntax. You forgot to end your statement on line 4 with a semicolon:

$arrbrowser = array("mozilla","opera","MSIE"); // put all the UA's in here