downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

SSL コンテキストオプション> <HTTP コンテキストオプション
Last updated: Fri, 13 Nov 2009

view this page in

FTP コンテキストオプション

FTP コンテキストオプションFTP コンテキストオプションの一覧

説明

ftp:// および ftps:// トランスポート用のコンテキストオプションです。

オプション

overwrite boolean

リモートサーバ上の既存のファイルに対する上書きを許可する。 書き込みモード(アップロード)時のみ有効。

デフォルトは FALSE です。

resume_pos integer

転送を開始するファイル内の位置。 読み込みモード(ダウンロード)時のみ有効。

デフォルトは 0 (ファイルの先頭) です。

proxy string

FTP リクエストを、http プロキシサーバ経由で行う。 ファイルの読み込み操作にのみ適用される。 例: tcp://squid.example.com:8000

変更履歴

バージョン 説明
5.1.0 proxy が追加されました。
5.0.0 overwrite および resume_pos が追加されました。

注意

注意: 基盤となるソケットストリームのコンテキストオプション
これ以外のコンテキストオプションが 基盤となるトランスポート でサポートされています。 ftp:// ストリームの場合は、tcp:// のコンテキストオプションを参照ください。 ftps:// ストリームの場合は、ssl:// のコンテキストオプションを参照ください。



add a note add a note User Contributed Notes
FTP コンテキストオプション
php dot net at misterchucker dot com
16-Apr-2009 01:19
This is an example of how to allow fopen() to overwrite a file on an FTP site. If the stream context is not modified, an error will occur: "...failed to open stream: Remote file already exists and overwrite context option not specified...".

<?php
// The path to the FTP file, including login arguments
$ftp_path = 'ftp://username:password@example.com/example.txt';

// Allows overwriting of existing files on the remote FTP server
$stream_options = array('ftp' => array('overwrite' => true));

// Creates a stream context resource with the defined options
$stream_context = stream_context_create($stream_options);

// Opens the file for writing and truncates it to zero length
if ($fh = fopen($ftp_path, 'w', 0, $stream_context))
{
   
// Writes contents to the file
   
fputs($fh, 'example contents');
   
   
// Closes the file handle
   
fclose($fh);
}
else
{
    die(
'Could not open file.');
}
?>

 
show source | credits | sitemap | contact | advertising | mirror sites