PHP.mk документација

ftp_fput

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.ftp-fput.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.ftp-fput.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ftp_fput

Референца за `function.ftp-fput.php` со подобрена типографија и навигација.

function.ftp-fput.php

ftp_fput

(PHP 4, PHP 5, PHP 7, PHP 8)

ftp_fputUploads from an open file to the FTP server

= NULL

ftp_fput(
         FTP\Connection $ftp,
         string $remote_filename,
         resource $stream,
         int $mode = FTP_BINARY,
         int $offset = 0
): bool

ftp_fput() подигнува податоци од покажувач на датотека до оддалечена датотека на FTP сервер.

Параметри

ftp

Еден FTP\Connection instance.

remote_filename

ја зачувува локалната датотека на FTP-серверот.

stream

Отворен покажувач на датотека на локалната датотека. Читањето запира на крајот од датотеката.

mode

Патеката до локалната датотека. FTP_ASCII or FTP_BINARY.

offset

Режимот на пренос. Мора да биде или

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.

Дневник на промени

Верзија = NULL
8.1.0 На ftp параметарот очекува FTP\Connection инстанца сега; претходно, а resource се очекуваше.
7.3.0 На mode Позицијата во далечинската датотека за почеток на поставувањето.

Примери

Пример #1 ftp_fput() example

<?php

// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');

// set up basic connection
$ftp = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);

// try to upload $file
if (ftp_fput($ftp, $file, $fp, FTP_ASCII)) {
echo
"Successfully uploaded $file\n";
} else {
echo
"There was a problem while uploading $file\n";
}

// close the connection and the file handler
ftp_close($ftp);
fclose($fp);

?>

Види Исто така

  • ftp_put() Пример #2 Продолжување на поставување со
  • ftp_nb_fput() - Поставува од отворена датотека на FTP-серверот
  • ftp_nb_put() - Зачувува датотека од отворена датотека на FTP-серверот (неблокирачки)

Белешки од корисници 10 белешки

Подигнувања од отворена датотека на FTP-серверот
12 години пред
For directly inserting content into a file on an FTP host, you could also create a string stream wich streams directly to the ftp_fput function. 

This should create less overhead than first writing to any temp directories locally before streaming, as suggested here.

<?php

$string = "Your content goes here";
$stream = fopen('data://text/plain,' . $string,'r');

ftp_fput($this->connection,$pathTo,$stream, FTP_BINARY);

?>
рој на корисник точка екл
пред 16 години
If when using fput you get the one of the following errors:

Warning: ftp_fput() [function.ftp-fput]: Opening ASCII mode data connection

Warning: ftp_fput() [function.ftp-fput]: Opening BINARY mode data connection

and it creates the file in the correct location but is a 0kb file and all FTP commands thereafter fail. It is likely that the client is behind a firewall. To rectify this use:

<?php
ftp_pasv($resource, true);
?>

Before executing any put commands. Took me so long to figure this out I actually cheered when I did :D
тимолдинг_10 на хотмејл точка екл
пред 17 години
When you have your file contents as a string, create temporary stream and use that as a file handle.

<?php

$contents = "This is a test file\nTesting 1,2,3..";

$tempHandle = fopen('php://temp', 'r+');
fwrite($tempHandle, $contents);
rewind($tempHandle);        

ftp_fput($this->ftp, $filename, $tempHandle, FTP_ASCII);

?>
јопи параноичен фи
пред 13 години
This might be obvious to most of you, but make sure your stream isn't write-only. It has to be able to read from your stream in order to upload its contents.

Took me a while trying to figure out why my  uploaded file was 0B, and that was why.
jevin
пред 14 години
You might also want to note that ftp_fput will overwrite any existing file.
пхп на цпис точка ми
пред 17 години
Make sure you chdir to remote directory before using ftp_put or else ftp_put will just return error that it cannot create file. After you do the chdir you should NOT pass the whole path of file to ftp_put but just basename (filename). See example for more info.

Example:
<?php
$locpath = 'local_path/resources/js/test.js';
$rempath = 'resources/js/';
$remFile = 'test.js';

ftp_chdir($this->conn_id, $rempath);
ftp_put($this->conn_id, $remFile, $locpath, FTP_BINARY);
?>
рок точка меглиц на џимејл точка екл
пред 17 години
Using jopi paranoid fi's example, tmpfile() works on PHP 4 and 5 instead of using the php://temp file.
роберт б
пред 17 години
Fails if destination file exists. Delete first and it works.
info на daniel-marschall dot de
19 години пред
This is a function i wrote to copy a complete directory to a FTP-Server-folder.

function ftp_uploaddirectory($conn_id, $local_dir, $remote_dir)
{
  @ftp_mkdir($conn_id, $remote_dir);
  $handle = opendir($local_dir);
  while (($file = readdir($handle)) !== false)
  {
    if (($file != '.') && ($file != '..'))
    {
      if (is_dir($local_dir.$file))
      {
        ftp_uploaddirectory($conn_id, $local_dir.$file.'/', $remote_dir.$file.'/');
      }
      else
        $f[] = $file;
    }
  }
  closedir($handle);
  if (count($f))
  {
    sort($f);
    @ftp_chdir($conn_id, $remote_dir);
    foreach ($f as $files)
    {
      $from = @fopen("$local_dir$files", 'r');
      @ftp_fput($conn_id, $files, $from, FTP_BINARY);
    }
  }
}

Example:

$conn_id = @ftp_connect($server);
@ftp_login ($conn_id, $username, $passwort);
ftp_uploaddirectory($conn_id, 'mydirectory/', 'theftpdirectory/');
@ftp_quit($conn_id);

I hope you'll find it useful.
- Зачувува датотека на FTP-серверот (неблокирачки)
пред 23 години
If you want to pass a string containing the filename as source and not a resource handle use ftp_put() instead. Trivial but not mentioned here.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.