简体   繁体   English

如何使用COPY命令将文件从本地复制到php中的服务器路径

[英]How to copy a file from local to server path in php using COPY command

How to copy local file from my xampp directory to server path.如何将本地文件从我的 xampp 目录复制到服务器路径。 I have tried this code.我试过这个代码。 I am still wondering Do I need ftp user name and password for this?我仍然想知道我是否需要 ftp 用户名和密码?

<?php
$remote_file_url = 'http://HOST_NAME/folder1/folder2/';
$local_file = '05fad57.jpg';
$copy = copy( $local_file,$remote_file_url);
?>

Any help would be greate任何帮助都会很棒

You can't copy a file from one location to another using HTTP.您不能使用 HTTP 将文件从一个位置复制到另一个位置。 One possibility is to use FTP as you already stated, but this does depend on the capabilities of the remote server.一种可能性是使用您已经说过的 FTP,但这确实取决于远程服务器的功能。

File must in ZIP format then you can do this using copy()文件必须为 ZIP 格式,然后您可以使用copy()

/* Source File URL */
$remote_file_url = 'http://server-url/files.zip';  
 
/* New file name and path for this file */
$local_file = 'files.zip';  
 
/* Copy the file from source url to server */ 
$copy = copy( $remote_file_url, $local_file );  
 
/* Add notice for success/failure */
if( !$copy ) {
    echo "failed to copy $file...\n";
}
else{
    echo " success to copy $file...\n";
}

Good tutorial check here 好的教程在这里检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM