php实现ftp上传,PHP_PHP实现ftp上传文件示例,FTP上传是PHP实现的一个常见且 - phpStudy...
PHP實現ftp上傳文件示例
FTP上傳是PHP實現的一個常見且非常重要的應用技巧,今天就來與大家分享一下PHP實現FTP上傳文件的簡單示例。希望對大家的PHP學習能帶來一定的幫助。
主要代碼如下:
function make_directory($ftp_stream, $dir){
// if directory already exists or can be immediately created return true
if ($this->ftp_is_dir($ftp_stream, $dir) || @ftp_mkdir($ftp_stream, $dir)) return true;
// otherwise recursively try to make the directory
if (!$this->make_directory($ftp_stream, dirname($dir))) return false;
// final step to create the directory
return ftp_mkdir($ftp_stream, $dir);
}
function ftp_is_dir($ftp_stream, $dir){
// get current directory
$original_directory = ftp_pwd($ftp_stream);
// test if you can change directory to $dir
// suppress errors in case $dir is not a file or not a directory
if ( @ftp_chdir( $ftp_stream, $dir ) ) {
// If it is a directory, then change the directory back to the original directory
ftp_chdir( $ftp_stream, $original_directory );
return true;
} else {
return false;
}
}
$conn = ftp_connect("ftp地址") or die("Could not connect");
ftp_login($conn,"ftpname","password");
//利用ftp創建目錄
make_directory($conn,$path);
//利用ftp選擇進入目錄
ftp_chdir($conn,$path);
//開始上傳
if(ftp_put($conn,$info[0]['savename'],getcwd().$upload->savePath.$info[0]['savename'],FTP_BINARY)){
unlink(getcwd().$upload->savePath.$info[0]['savename']);
}
ftp_close($conn);
//注意上傳端的ftp權限設置
感興趣的朋友可以測試運行或改寫本文所述代碼,加深理解的同時可以讓代碼功能更加完善。相關閱讀:
ASP.NET實現根據URL生成網頁縮略圖的方法
PHP中使用php5-ffmpeg擷取視頻圖片實例
C#獲取圖片文件擴展名的方法
Linux折騰記(十四):優秀的文本化編輯思想大碰撞(Markdown、LaTeX、MathJax)
javascript常用方法總結
Jquery Mobile 自定義按鈕圖標
win10安裝realtek聲卡驅動超時沒有聲音的解決方法
C#下listview如何插入圖片
C++線程同步實例分析
win10怎么升級?win10升級注意事項
Win10正式版C盤inetpub文件夾刪不掉怎么辦?如何解決?
Javascript之BOM(window對象)詳解
深入理解Javascript里的依賴注入
AngularJS應用開發思維之依賴注入3
總結
以上是生活随笔為你收集整理的php实现ftp上传,PHP_PHP实现ftp上传文件示例,FTP上传是PHP实现的一个常见且 - phpStudy...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 记录重要的NLP学习资源链接
- 下一篇: Linux版本JDK1.8下载与安装