Jump to content

[SOLVED] Photo display For Member


CBaZ

Recommended Posts

I have a question.  I have my photos displayed via $_SESSION[id]

so I am trying to use <img src=$_SESSION[id] which is fine and all matches the name of the file but for extensions and multiple extension I am not sure how to script it so that it holds the extensions as well.

 

also I need to have an if statement in place when the SESSION[id].gif jpg whatever does not exist I have a nopic.gif in place if there is no member chose photo yet..

 

can anyone please help? thanks.

Link to comment
https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/
Share on other sites

You can't call the file without the extension, you could always do something like:

 

if(file_exists("$_SESSION[id].gif")){
$pic = "$_SESSION[id].gif";
}else {
if(file_exists("$_SESSION[id].jpg")){
$pic = "$_SESSION[id].jpg";
}else {
if(file_exists("$_SESSION[id].bmp")){
$pic = "$_SESSION[id].bmp";
}else {
$pic = "nopic.gif";
}

 

Try that.

i get an unexpected $end error

 

if (file_exists ("$_SESSION[id].gif")) {

$pic = "$_SESSION[id].gif";

} else {

if (file_exists ("$_SESSION[id].jpg")) {

$pic = "$_SESSION[id].jpg";

} else {

if (file_exists ("$_SESSION[id].bmp")) {

$pic = "$_SESSION[id].bmp";

} else {

$pic = "nopic.gif";

Quick way to solve case issues is simply compare variables utilising a command to $upper[id]....

 

Or, change the upload script to upper case or lower case the filenames. You'll not have to worry about it in the future with any code. Saves you a few lines here and there.

 

 

<?php

session_start();

include "config.php";

if (!isset($_SESSION['logged'])) { 

// not logged in 

header("Location: index.php");

}

$username = $_SESSION['username'];

$maxfilesize = 81920;

// check if there was a file uploaded

if (!is_uploaded_file($_FILES['userphoto']['tmp_name'])) {

    $error = "you didn't select a file to upload.<br />";

// if it was, go ahead with other checks

} else {

    if ($_FILES['userphoto']['size'] > $maxfilesize) {

        $error = "your image file was too large.<br />";

        unlink($_FILES['userphoto']['tmp_name']);

    } else {

        $ext = strrchr($_FILES['userphoto']['name'], ".");

        if ($ext != ".gif" AND $ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".bmp" AND $ext != ".GIF" AND $ext != ".JPG" AND $ext != ".JPEG" AND $ext != ".BMP") {

            $error = "your file was an unacceptable type.<br />";

            unlink($_FILES['userphoto']['tmp_name']);

        // if it's there, an okay size and type, copy to server and update the photo value in SQL

        } else {

            if ($_SESSION['photo'] != "profiles/photos/nopic.gif") {

                unlink("profiles/photos/".$_SESSION['photo']);

            }

            $newname = $_SESSION[id].$ext;

            move_uploaded_file($_FILES['userphoto']['tmp_name'],"profiles/photos/".$newname);

            mysql_query("UPDATE users SET photo='$newname' WHERE username='$username'") or die (mysql_error());

            $_SESSION['photo'] = $newname;

        }

    }

}

?>

<html><head><title>Change Photo Result</title>

<link rel="stylesheet" type="text/css" href="style.css">

</head><body>

<h1>Change Photo Result</h1>

<?php

session_start();

include "config.php";

if (!isset($_SESSION['logged'])) { 

// not logged in 

header("Location: MaloriaN.php");

}

?>

<?php

if ($error) {

    echo "Your photo could not be changed because ".$error.".";

} else {

$id =<?echo $_SESSION['id']; ?> 

echo "Your photo was successfully uploaded.  To view your updated profile, <a href=\"update.php?user_id=$id\">click here</a>.";

}

 

?></body></html>

 

this is what the uploader php looks like maybe this can be done better to make the if's work :)

 

 

 

 

if i have the code like this

<?php

if (!$_SESSION[id].gif) {

$pic = "$_SESSION[id].gif";

} else {

$pic = "nopic.gif"

}

?>

it always shows the users photo even if it does not exist it attempts to show it.

i don't understand why it doesnt check correctly it is uploaded and then goes to nopic.gif if none is there.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.