CBaZ Posted July 11, 2007 Share Posted July 11, 2007 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 More sharing options...
marcus Posted July 11, 2007 Share Posted July 11, 2007 if(!$_SESSION[id]){ $pic = "nopic.gif"; }else { $pic = $_SESSION[id]; } Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295598 Share on other sites More sharing options...
CBaZ Posted July 11, 2007 Author Share Posted July 11, 2007 how about for the extension of the pic $_SESSION[id] only gives the number like 90 but it doesn't include .jpg .gif .bmp etc Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295605 Share on other sites More sharing options...
marcus Posted July 11, 2007 Share Posted July 11, 2007 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. Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295608 Share on other sites More sharing options...
CBaZ Posted July 11, 2007 Author Share Posted July 11, 2007 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"; Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295624 Share on other sites More sharing options...
marcus Posted July 11, 2007 Share Posted July 11, 2007 try: if(file_exists("$_SESSION[id].gif")){ $pic = "$_SESSION[id].gif"; } if(file_exists("$_SESSION[id].jpg")){ $pic = "$_SESSION[id].jpg"; } if(file_exists("$_SESSION[id].bmp")){ $pic = "$_SESSION[id].bmp"; }else { $pic = "nopic.gif"; } Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295629 Share on other sites More sharing options...
CBaZ Posted July 11, 2007 Author Share Posted July 11, 2007 now eventhough there is a pic there it only shows nopic.gif Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295642 Share on other sites More sharing options...
marcus Posted July 11, 2007 Share Posted July 11, 2007 File extensions are case sensitive, so say you have JPG, but you were asking for jpg it wouldn't read it the same way. Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295647 Share on other sites More sharing options...
CBaZ Posted July 11, 2007 Author Share Posted July 11, 2007 yea all are sensitive something even after uploading its still saying nopic.gif only Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295656 Share on other sites More sharing options...
marcus Posted July 11, 2007 Share Posted July 11, 2007 While calling for the file, add in your home directory to where the images are "/home/username/public_html/folder/$_SESSION[id].gif" Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295657 Share on other sites More sharing options...
CBaZ Posted July 11, 2007 Author Share Posted July 11, 2007 yea it locates the folder due to my other script but it just doesn't look for the files weird. Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295812 Share on other sites More sharing options...
CBaZ Posted July 12, 2007 Author Share Posted July 12, 2007 I have figured out the problem its that $pic = can only identify one time not multiple i'd have to use $pic2 = jpg pic3= bmp etc. that's why its not working Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-295908 Share on other sites More sharing options...
EmperorJazzy Posted July 12, 2007 Share Posted July 12, 2007 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. Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-296024 Share on other sites More sharing options...
CBaZ Posted July 12, 2007 Author Share Posted July 12, 2007 <?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 Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-296055 Share on other sites More sharing options...
CBaZ Posted July 12, 2007 Author Share Posted July 12, 2007 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. Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-296365 Share on other sites More sharing options...
CBaZ Posted July 12, 2007 Author Share Posted July 12, 2007 I have solved this one myself now so thanks for your help Link to comment https://forums.phpfreaks.com/topic/59482-solved-photo-display-for-member/#findComment-296515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.