PHP实现文件上传的一种好方法_PHP

WBOY
Release: 2016-06-01 12:34:56
Original
867 people have browsed it

P>       网上很的免费支持PHP的个人主页空间现在不少,这时可能会想到来个上传什么的,但毕竟属于免费的,当然会有很多的限制,不允许上传,这个很正常,有的连Mail()函数都不给用呢。遇到这种情况,也不是没有办法上传的哦,PHP支持强大的socket,当然少不了直接操作ftp了,看看函数表上就有了,通过ftp实现文件上传。不是很好,我们上传主页不是用ftp上传吗。

   实现代码如下:


//upload.php



 
上传文件:   
 
 

$ftp_server="ftp服务器(最好用IP)"; 
$ftp_username="ftp用户名"; 
$ftp_password="登录密码"; 
$ftp_dir="目录(如设置为 /)";

if ($action == "OK") 

  $con = ftp_connect($ftp_server);  //连接ftp
  ftp_login($con, $ftp_username, $ftp_password); //用户登录
  $suss=$con;
  ftp_chdir($suss, $ftp_dir);  //cd到指定目录

  $ok_code = ftp_put($suss, $upload_file_name, $upload_file, FTP_BINARY); //put文件
 
  if ($ok_code == 1) 
  { 
      echo "文件上传成功!\n"; 
  } 
  else 
  { 
     echo "文件上传失败!\n"; 
  } 
    ftp_quit($suss);  // 关闭ftp连接

?> 

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!