Page 1 of 1

getting images from folder using session

Posted: Wed Feb 09, 2005 2:35 am
by pleigh
i created a folder for images. i want my program to be like this, if the user entered his username and password, his picture will be displayed to the index page.

my question is, what syntax should i use to access or get the jpg file to be displayed in the index page

tnx

pleigh :cry:

Posted: Wed Feb 09, 2005 2:43 am
by feyd
you'd need to know what filename to load, this should be stored in the database in the user's settings (hidden from their direct control).

It's then a matter of knowing if the file is there and then writing out the image tag into the html stream.

Posted: Wed Feb 09, 2005 2:43 am
by n00b Saibot
what syntax are you applying for naming images.

I suggest you name them on the username they correspond to.

then afterwards you can put img src in page using username var.

Posted: Wed Feb 09, 2005 9:50 am
by PrObLeM
feyd wrote:you'd need to know what filename to load, this should be stored in the database in the user's settings (hidden from their direct control).

It's then a matter of knowing if the file is there and then writing out the image tag into the html stream.

im going to have to agree with fyed its the best solution sorry n00b Saibot even though your solution will work, but putting the information in the database is better

...

Posted: Wed Feb 09, 2005 11:13 am
by s.dot
Assuming your information is in a database, I would do this,

Create your login box linking to a script to validate login / in this example "login.php"

Code: Select all

<? //login box ?> 
<form action="login.php" method="post">
<input type="hidden" name="action" value="login">

username<BR>
<input type="text" name="username" size="20"><BR><BR>
password<BR>
<input type="password" name="password" size="20"><BR>
<input type="submit" value="Login">
</form>
Then, this would be your login.php page

Code: Select all

<?

if($action == "login")&#123;

// perform code here that validates user's existence
// If user exists, go to page where you want picture to appear
$username = $_POST&#1111;'username'];
header("Location: index.php?username=$username"); &#125;
?>
Then to display their picture on the page where you want it to appear

Code: Select all

<? $sql = "SELECT picturename FROM database_table WHERE username = '$username'";
$result = mysql_query($sql); ?>
<img src="/path/to/your/pictures/<? echo $result; ?>">

Posted: Wed Feb 09, 2005 11:59 pm
by n00b Saibot
PrObLeM wrote: sorry n00b Saibot even though your solution will work, but putting the information in the database is better
:lol: My solution doesn't involve overhead on a db connection. it would be much faster my way. but anyway, I think atleast he is much better informed now to take decision on his own :wink:

Posted: Thu Feb 10, 2005 12:22 am
by feyd
needing a database connection to find information all depends on what you have cached off in say.. a filesystem session... if the system already incorporates a query against the table holding the data, it doesn't add more than a few milliseconds (at most). But let's face it, php, along with pretty much all the other interpretted scripting language, isn't the fastest kid on the block...