Home > php教程 > PHP源码 > php实现curl模拟ftp上传的方法_php技巧

php实现curl模拟ftp上传的方法_php技巧

PHP中文网
Release: 2016-05-25 17:04:10
Original
1520 people have browsed it

这篇文章主要介绍了php实现curl模拟ftp上传的方法,实例分析了php基于curl实现FTP传输文件的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下

本文实例讲述了php实现curl模拟ftp上传的方法。分享给大家供大家参考。具体如下:

<?php
function upload($dir,$src,$dest)
{
  $ch = curl_init();
  $fp = fopen($src, &#39;r&#39;);
  curl_setopt($ch, CURLOPT_URL, &#39;ftp://user:pwd@host/interpretation/&#39;.$dir .&#39;/&#39;. $dest);
  curl_setopt($ch, CURLOPT_UPLOAD, 1);
  curl_setopt($ch, CURLOPT_INFILE, $fp);
  curl_setopt($ch, CURLOPT_INFILESIZE, filesize($src));
  curl_exec ($ch);
  $error_no = curl_errno($ch);
  curl_close ($ch);
  if ($error_no != 0)
  {
     return 0;
  }else{
   return 1;
  }
} 
upload("images","s.py","aaa.py");
?>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template