SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Bandwidthbyday problems

    hi guys, i;ve got a problem.. i host files and the maxbandwidthbyday didn't work at all...
    the one that is working is when user sign up and the bandwidth will follow what i;ve set. if a guest upload a file, the daily bandwidth doesn't follow the settings that i've configure. is there anything wrong with this output?

    this script is the outgoing file which users can view the image.
    please help.

    PHP Code:
    <?
    include "database.php";
    include 
    "config.php";
    $db=new database($sql_host,$sql_user,$sql_pass,$sql_database,"");

    $path=$HTTP_SERVER_VARS["PHP_SELF"];
    $last=strrpos($path,'/');
    $type=substr($path,$last+1,1);
    $id=intval(substr($path,$last+2));

    $suspended_file='images/SUSPEND.jpg';
    $deleted_file='images/NotFound.gif';
    $overbandwidth_file='images/Bandwidth.jpg';
    $db->setQuery("select i.file,i.name,i.uid,i.size,i.bandwidth,u.bandwidth as userbandwidth,g.bandwidth as maxbandwidth,lastview as lview,u.status
                   from images as i
                   left join users as u on u.id=i.uid
                   left join groups as g on g.id=u.gid
                   where i.id='
    $id'");
    $db->query();
    $row=$db->loadRow();
    $filetype=substr(strtolower(strrchr($row[file],'.')),1);

    //can't find image record in db
    if(!$row)
    {
        
    $file=$deleted_file;
        
    $error=1;
    }
    //user is suspended
    if($row[status]==-1)
    {
       
    $file=$suspended_file;
       
    $error=1;
    }
    //check bandwidth
    if($row[uid]==0)
    {
        
    $ld=date('n',$row[lview]);
        
    $cd=date('n',$time);
        if(
    $ld==$cd)
        {
            
    $db->setQuery("SELECT * FROM setting");
            
    $db->query();
            
    $SET=$db->loadRow();
            if(
    $SET[maxbandwidthbyday]<$row[bandwidth])
            {
                
    $file=$overbandwidth_file;
                
    $error=1;
            }
        }
    }
    elseif(
    $row[userbandwidth]>$row[maxbandwidth])
    {
        
    $file=$overbandwidth_file;
        
    $error=1;
    }
    elseif(
    $SET[maxbandwidthbyday]>$row[bandwidth])
    {
        
    $file=$overbandwidth_file;
        
    $error=1;
    }
    there are more stuff below but it doesn't consent the bandwidth.

  2. #2
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Try this:

    PHP Code:
    $SET[maxbandwidthbyday]<$row[bandwidth
    Should be:

    PHP Code:
    $SET['maxbandwidthbyday']<$row['bandwidth'
    The thing is, if you write maxbandwidthbyday PHP expects it to be a CONSTANT, which you haven't defined. If you put it in apostrophes, PHP will search through the array to look for a key called 'maxbandwidthbyday', which is what you want.

  3. #3
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If the constant is undefined, PHP will be really nice by treating it as if you put it in single quotes, so this won't fix the problem.

    Quote Originally Posted by http://us3.php.net/types.array
    This is wrong, but it works. Then, why is it wrong? The reason is that this code has an undefined constant rather than a string, and PHP may in future define constants which, unfortunately for your code, have the same name. It works because PHP automatically converts a bare string (an unquoted string which does not correspond to any known symbol) into a string which contains the bare string. For instance, if there is no defined constant named bar, then PHP will substitute in the string 'bar' and use that.
    There's too much missing to actually answer this question, though. Do some debugging, I'm sure you'll work it out.

  4. #4
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Ah ok, my bad. Pretty crappy functionality though, if you ask me. Makes debugging all the more difficult...

    Live and learn

  5. #5
    SitePoint Guru
    Join Date
    Jul 2005
    Location
    Orlando
    Posts
    634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like $SET (the db row containing the settings) is only getting created if there is a uid (if the user is logged in).

    But the if that uses it later on is an else to the if that creates it..

    I'm sorry if that's not clear, but let me try this:

    Case 1. User is logged in. They go through the first if in the if/else sequence at the bottom. It checks how much bandwidth they can use per the $SET array. That works fine.

    Case 2: User isn't logged in. They go through the last if in the if/else sequence. But $SET is empty because they didn't go through the first if, so it doesn't trigger.

    Unless $SET is also being set in the config include file?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •