supermerc Posted December 24, 2006 Share Posted December 24, 2006 Hey I have this code to upload an aviatar to a folder. But everytime I upload one it doesnt work because instead of saving it as the username then .gif It just names it .gifThis is my code[code]<?session_start();$maxwidth = "250"; // Max width allowed for avatars$maxheight = "250"; // Max height allowed for avatarsif (isset($_POST['uploadit'])) {$filetype = $_FILES['userfile']['type'];$filetypex = substr($filetype,0,5);if ($filetypex == image) {$newid = "userimage/";$newid .= "$s_username";$newid .= ".gif";$mysock = getimagesize($_FILES['userfile']['tmp_name']);$imagewidth = $mysock[0];$imageheight = $mysock[1];if ($imagewidth <= "$maxwidth" && $imageheight <= "$maxheight") {if(!(copy($_FILES['userfile']['tmp_name'], $newid))) die("Cannot upload files.");echo "Your New Avatar Has Been Created";}else {echo "This avatar is to big, please change it";}}else {echo "This File Is Not a Image Fool";}}else {if(isset($_SESSION['s_logged_n'])){ $session_username = $_SESSION['s_username'];$filename = 'userimage/'.$s_username.'.gif';if (file_exists($filename)) {echo '<img src="'.$filename.'" border="1">';}else {echo "You Do Not Have An Avatar";}?><form action="<?=$_SERVER['REQUEST_URI'] ?>" method="post" enctype="multipart/form-data">Select a file <input type="file" name="userfile" size="18"><br><input type="submit" value="Upload My Avatar" name="uploadit" size="18"><br><br><i>All Files Will Be Converted To .gif<?}else {echo 'not logged in';}}?>[/code]please help me Link to comment https://forums.phpfreaks.com/topic/31761-solved-avatar-upload-trouble/ Share on other sites More sharing options...
Orio Posted December 24, 2006 Share Posted December 24, 2006 Where do you define $s_username ?I think it's supposed to be $_SESSION['username'], no?Orio. Link to comment https://forums.phpfreaks.com/topic/31761-solved-avatar-upload-trouble/#findComment-147292 Share on other sites More sharing options...
supermerc Posted December 24, 2006 Author Share Posted December 24, 2006 what do you mean? Link to comment https://forums.phpfreaks.com/topic/31761-solved-avatar-upload-trouble/#findComment-147295 Share on other sites More sharing options...
Orio Posted December 24, 2006 Share Posted December 24, 2006 You haven't given $s_username a value in the script, so when you call it, php just put's nothing instead of it. I believe you meant to write $_SESSION['s_username'] in that line (as I can see you using it further in the script).This is the line:[code]$newid .= "$s_username";[/code]I believe it should be:[code]$newid .= "$_SESSION['s_username']";[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/31761-solved-avatar-upload-trouble/#findComment-147336 Share on other sites More sharing options...
supermerc Posted December 24, 2006 Author Share Posted December 24, 2006 I did what you told me too and this is what i gotParse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/xgame/public_html/random/upload.php on line 12 Link to comment https://forums.phpfreaks.com/topic/31761-solved-avatar-upload-trouble/#findComment-147346 Share on other sites More sharing options...
Orio Posted December 24, 2006 Share Posted December 24, 2006 Remove the quotes and make sure it's exactly like this:[code]$newid .= $_SESSION['s_username'];[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/31761-solved-avatar-upload-trouble/#findComment-147360 Share on other sites More sharing options...
supermerc Posted December 24, 2006 Author Share Posted December 24, 2006 it works, thx alot man Link to comment https://forums.phpfreaks.com/topic/31761-solved-avatar-upload-trouble/#findComment-147364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.