problem with tempnam();

Discussion in 'PHP' started by crazy.works, Mar 30, 2009.

  1. #1
    hello,
    iam using tempnam function in one of my scripts , after i coded the script it works very well on the localhost , but when i uploaded it on my host it didnt work and i got that error

    
    Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php')
    
    PHP:
    so that is the code which cauzed the error from the tempnam func

    
    $data = "some data of mine";
    
    $temp_path=@tempnam("/tmp","");
    $fp = @fopen($temp_path,"wb");
    @fwrite($fp, $data );
    @fclose($fp);
    
    include($temp_path);
    @unlink($temp_path);
    
    
    PHP:

    there wasn't any addition includes on that file ,so the error come here from include($temp_path);

    so please , any idea for fixing that ?? and why it works on the localhost but doesn't works on my host ??

    thanks alot
     
    crazy.works, Mar 30, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you have @anything() in your code, then your code is broken. @ is a horrible crutch that keeps you from doing proper error-checking. It makes debugging more difficult and vastly increases the likelihood of your program doing something you didn't expect it to.

    Take those off and report on the error messages you get and you will have your answer.
     
    SmallPotatoes, Mar 30, 2009 IP
  3. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    First of all, who is saying /tmp is a dir in your host? Maybe locally yes...but not all servers are the same. perhaps make a dir called tmp in the location of the folder, then just use tempnam('tmp','');

    Try that.
     
    NatalicWolf, Mar 30, 2009 IP
  4. crazy.works

    crazy.works Peon

    Messages:
    304
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    well, thanks guys for that useful info .

    now i deleted the @ for the error reporting , and i found the tempnam is disabled .

    errors :-

    Warning: tempnam() has been disabled for security reasons

    Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php')

    so how can i enable it ???

    thanks
     
    crazy.works, Mar 31, 2009 IP
  5. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You don't...just write your own method.
    Just replace _tempnam with your tempnam

    PM me if you need help!

    function _tempnam()
    {
    $File=md5(microtime().$_SERVER['REMOTE_ADDR'].$_SERVER['REMOTE_PORT']);//Unique file
    fclose(fopen('/tmp/'.$File,'w+'));//Open file then close it...new file.
    return $File;
    }
     
    NatalicWolf, Mar 31, 2009 IP
  6. crazy.works

    crazy.works Peon

    Messages:
    304
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks alot ,i gonna contact the root to enable it from the php.ini file ,

    beside special thanks NatalicWolf ,your function is so great, i gonna try its way to make my own temp in the same directory .
     
    crazy.works, Mar 31, 2009 IP
  7. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Awesome to hear. I love to do things from scratch if when I have to. Just shows my creativity.
     
    NatalicWolf, Mar 31, 2009 IP