Simple FTP upload with PHP
2015-06-19

PHP,FTP,Snippets,EN

How to to upload a file to a FTP Server using PHP. There are several ways to accomplish this.

Using file_put_contents() command.


// FTP access data
$sUser     = 'developer';
$sPassword = 'secret';
$sHost     = 'ftp.example.com';

// file informations
$sFilename = 'file.txt';
$sContent  = 'Example Content. DateTime: ' . date('Y-m-d H:i:s');

// save the file
$bSuccess = (boolean) file_put_contents(

    // target FTP file 
    sp […]

PHP: Best way to get the first element of an array
2014-03-19

PHP,Snippets,EN

Q: how to determine the value of the first element of an array if the key is unknown ?

A: make use of the reset command to set the array pointer back to start and to get the value of the array's first element.


// associative array
$aArray = array(
    'foo' => 'bar', 
    'john' => 'doe'
);

// value of array's first element
$mValue = reset($aArray); // bar

// key of array's first element
$mKey = key(reset($aArray)); // foo

// value […]

Diese Website verwendet Cookies, um Ihnen den bestmöglichen Service zu gewährleisten. Weiterführende Informationen finden Sie in unserer Datenschutzerklärung. Klicken Sie in die nachfolgende Checkbox um Cookies zu akzeptieren. Bestätigen Sie anschließend durch Klick auf "Speichern".