Welcome Guest, Not a member yet? Register   Sign In
A simple get avatar function
#1

[eluser]Iwasignited[/eluser]
Hello everyone.
Its me again.
This time, I have a question.
I wrote:
Code:
function getAvatar($userid)
    {
        $extensions = array('.jpeg', '.jpg', '.png', '.gif');
        foreach ($extensions as $extension)
        {
            $check_this_name = $userid.$extension;
            $dest = ''. base_url() .'avatars/'. $check_this_name .'';
            if (file_exists($dest))
            {
                $filename = $check_this_name;
            }
        }
        if (!isset($filename))
        {
            $filename = 'noavatar.png';
        }
        return $filename;
    }

in my avatars folder, I placed a file named 5.jpg but my user whose userid = 5 (a test one) always receives 'noavatar.png' as the avatar.

Please let me know what Im doing wrong.

Thank you all.
#2

[eluser]Sbioko[/eluser]
Code:
var_dump($dest);
Put this after $dest declaration and watch the result. Try to paste this URL in the new tab and you'll see the errors you made.
#3

[eluser]Iwasignited[/eluser]
I dont understand

the destination var receives:
http://localhost/CMS/avatars/5.gif
http://localhost/CMS/avatars/5.jpeg
http://localhost/CMS/avatars/5.jpg
http://localhost/CMS/avatars/5.png
#4

[eluser]Sbioko[/eluser]
Aha, I understood the problem. Show your .htaccess file :-)
#5

[eluser]Iwasignited[/eluser]
I do not have one, should I create one?
#6

[eluser]Sbioko[/eluser]
Hm, do you work only with query strings?
#7

[eluser]Iwasignited[/eluser]
sorry but I dont know what it is ><
#8

[eluser]Sbioko[/eluser]
Ok, I'll talk in more understandable way. Does your urls look like: http://test.com/index.php?c=main&m=index&param=testing?
#9

[eluser]Iwasignited[/eluser]
no, its "../CMS/index.php/testing"
#10

[eluser]Iwasignited[/eluser]
any idea?




Theme © iAndrew 2016 - Forum software by © MyBB