Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php ftp连接和文件内容(ftp://)中,哪一个更可靠_Php_Heroku_Ftp_File Put Contents - Fatal编程技术网

在php ftp连接和文件内容(ftp://)中,哪一个更可靠

在php ftp连接和文件内容(ftp://)中,哪一个更可靠,php,heroku,ftp,file-put-contents,Php,Heroku,Ftp,File Put Contents,在我在heroku dyno上运行的php restful api中,由于我的api接受用户上传文件视图($_文件)-表单post-我需要将上传的文件转发到我的ftp服务器以保持它们,因为heroku没有存储 我搜索了一下,找到了实现这一目标的最佳方法,并找到了两种方法 代码示例显示了这两种方法 // common code: $tmp_file_path = $_FILES['image']['tmp_name']; $raw_filename = explode('.',$_FILES['i

在我在heroku dyno上运行的php restful api中,由于我的api接受用户上传文件视图($_文件)-表单post-我需要将上传的文件转发到我的ftp服务器以保持它们,因为heroku没有存储

我搜索了一下,找到了实现这一目标的最佳方法,并找到了两种方法

代码示例显示了这两种方法

// common code:
$tmp_file_path = $_FILES['image']['tmp_name'];
$raw_filename = explode('.',$_FILES['image']['name']);
$extention = array_pop($raw_filename);
$filename = md5(implode('.',$raw_filename)).$extention;

// 1st: ftp_put_content;
$content = file_get_contents($tmp_file_path);
// additional stream is required as per http://php.net/manual/en/function.file-put-contents.php#96217
$stream = stream_context_create(['ftp' => ['overwrite' => true]]); 
$upload_success = file_put_content('ftp://username:password@ftpserver.com/'+$filename, $content, 0, $stream);

// 2nd: ftp_put
$conn_id = ftp_connect("ftp.simpleinformatics.com");
$login_result = ftp_login($conn_id, "username", "password");
ftp_pasv($conn_id, true); //for somereason my ftp serve requires this !
if (!$conn_id OR !$login_result) $upload_success = false;
$ftp_upload_success = ftp_put($conn_id,'/'.$filename, $tmp_file_path);

echo "file_put_content" . ($upload_success ? "upload success" : 'file upload failed');

echo "ftp_put" . ($ftp_upload_success ? "upload success" : 'file upload failed');
我在我的ftp服务器上测试了这两种方法,两种方法都可以工作,但我担心可靠性,关于这两种方法如何工作的细节文档很少,所以我不确定这两种方法

  • 我可以在放入ftp文件时使用文件内容标志吗?像文件追加还是锁定
  • 如果上载到尚不存在的文件夹,会发生什么情况
  • 哪种方法更可靠,更不容易失败
  • 虽然文件内容不太详细,但我们需要在写入之前先读取文件内容,这会导致内存问题吗
  • FTP URL包装器支持从PHP 5开始追加:
  • 未使用任何方法创建FTP文件夹。你得自己处理
  • 太宽了
  • 不清楚
  • FTP URL包装器支持从PHP 5开始追加:
  • 未使用任何方法创建FTP文件夹。你得自己处理
  • 太宽了
  • 不清楚

  • 没有读过大部分文章,但按标题看,我认为
    ftp.*
    函数更可靠,因为这些协议的文件包装器可以被禁用。@JonStirling ftp.*处理文件附加/文件锁定/创建目录(如果不存在)?没有读过大部分文章,但按标题看,我想说
    ftp.*
    函数更可靠,因为这些协议的文件包装器可以被禁用。@JonStirling ftp.*是否处理文件附加/文件锁定/创建目录(如果不存在)?