Skip to content
Advertisement

tempnam() not working on client server

I did a script, which has to load a file from a ftp-server then parses it. The code relies on tempname to store the temporarily store the ftp-file. On my developement server (with php 5.3.10), this works flawlessly, however on the client machine (with php 5.2.17) it does not and gives me:

Warning: ftp_rawlist() [function.ftp-rawlist]: Unable to create temporary file. Check permissions in temporary files directory.

Can someone give me a clue what i could do? (I am a little weak on the possibiities of php)

I used this code:

define ("LOCALFILE",tempnam('/tmp', 'data-'));
define ("USER","myusername");
define ("PASS","mypassword");
define('SERVER', "ftpserver.com");
define ("DIR","/path/");

function getFTPFile(){

    // connect
    if(!($conn_id = @ftp_connect(SERVER))){
        Error::throwOne("Could not connect to ".SERVER);

    };
    // login 
    if(!($login_result = @ftp_login($conn_id, USER, PASS))){
        Error::throwOne("LOGIN INCORRECT! user:".USER." pass:".PASS);
    };
    // try to change the directory to somedir
    if (!ftp_chdir($conn_id, DIR)) {
        Error::throwOne("Couldn't change directoryn");
    }; 

    if(!($a = ftp_rawlist($conn_id, '-1t'))){
        Error::throwOne("Couldn't get ftp_rawlistn");
    };

    $server_file=($a[0]);
    if (!ftp_get($conn_id, LOCALFILE, $server_file, FTP_BINARY)) {
        Error::throwOne("Couldn't get filen");
    };
    ftp_close($conn_id);    
};

Advertisement

Answer

I found the issue. Since my hoster does not like the /tmp directory ( who would blame them ) i need to first set putenv(‘TMPDIR=/the tmp-dir my provider gave me’); which then works with tempname

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement