日期:2010-11-19 09:47:00 来源:本站整理
php curl模拟ftp文件上传代码[网站编程]
本文“php curl模拟ftp文件上传代码[网站编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
php curl模拟ftp文件上传代码
- <body>
- <form action="curlupload.php" method="post" enctype="multipart/form-data">
- <div>
- <label for="upload">select file</label>
- <input name="upload" type="file" />
- <input type="submit" name="submit" value="upload" />
- </div>
- </form>
- </body>
- </html>
- <?
- if (isset($_post['submit'])) {
- if (!empty($_files['upload']['name'])) {
- $ch = curl_init();
- $localfile = $_files['upload']['tmp_name'];
- $fp = fopen($localfile, 'r');
- curl_setopt($ch, curlopt_url, 'ftp://ftp_login:password@ftp.domain.com/'.$_files['upload']['name']);
- curl_setopt($ch, curlopt_upload, 1);
- curl_setopt($ch, curlopt_infile, $fp);
- curl_setopt($ch, curlopt_infilesize, filesize($localfile));
- curl_exec ($ch);
- $error_no = curl_errno($ch);
- curl_close ($ch);
- if ($error_no == 0) {
- $error = 'file uploaded succesfully.';
- } else {
- $error = 'file upload error.';
- }
- } else {
- $error = 'please select a file.';
- }
- }
- ?>
好了下面封闭成类了
- <?php
- class curl_ftp
- {
- private $ftpname; //ftp用户名
- private $ftppaw; //ftp密码
- private $urlftp; //ftp地址
- private $filename; //文件名
- public __construct($name, $password, $ftp)
- {
- $this->ftpname = $name;
- $this->ftppaw = $password;
- $this->urlftp = $ftp;
- // $this->filename = $filename;
- }
- public function getftp()
- {
- if (isset($_post['submit']))
- {
- if (!empty($_files['upload']['name']))
- {
- $ch = curl_init();
- $this->filename = $_files['upload']['tmp_name'];
- $fp = fopen($this->filename, 'r');
- curl_setopt($ch, curlopt_url, $this->ftp.$this->filename);
- curl_setopt($ch, curlopt_userpwd, "$name:password");
- curl_setopt($ch, curlopt_upload, 1);
- curl_setopt($ch, curlopt_infile, $fp);
- curl_setopt($ch, curlopt_infilesize, filesize($this->filename));
- curl_exec ($ch);
- $error_no = curl_errno($ch);
- curl_close ($ch);
- if ($error_no == 0)
- {
- $error = '文件上传成功';
- }
- else
- {
- $error = '文件上传失利';
- }
- }
- else
- {
- $error = '未挑选文件';
- }
- }
- }
- }
以上是“php curl模拟ftp文件上传代码[网站编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论