note 96217 modified in function.file-put-contents by danbrown

From: Date: Mon, 15 Feb 2010 21:04:00 +0000
Subject: note 96217 modified in function.file-put-contents by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165984@lists.php.net to get a copy of this message
Please note that when saving using an FTP host, an additional stream context must be passed through telling PHP to overwrite the file. <?php /* set the FTP hostname */ $user = "test"; $pass = "myFTP"; $host = "example.com"; $file = "test.txt"; $hostname = $user . ":" . $pass . "@" . $host . "/" . $file; /* the file content */ $content = "this is just a test."; /* create a stream context telling PHP to overwrite the file */ $options = array('ftp' => array('overwrite' => true)); $stream = stream_context_create($options); /* and finally, put the contents */ file_put_contents($hostname, $content, 0, $stream); ?> --was-- Please note that when saving using an FTP host, an additional stream context must be passed through telling PHP to overwrite the file. <?php /* set the FTP hostname */ $user = "test"; $pass = "myFTP"; $host = "host.com"; $file = "test.txt"; $hostname = $user . ":" . $pass . "@" . $host . "/" . $file; /* the file content */ $content = "this is just a test."; /* create a stream context telling PHP to overwrite the file */ $options = array('ftp' => array('overwrite' => true)); $stream = stream_context_create($options); /* and finally, put the contents */ file_put_contents($hostname, $content, 0, $stream); ?> http://php.net/manual/en/function.file-put-contents.php

« previous php.notes (#165984) next »