再一次,我需要一些专家非常感谢的帮助:)我正试图使用PHP的FTP函数通过web表单将文件上传到服务器上,我花了一天的时间在谷歌上搜索一个简单的教程,但大多数人似乎希望对这个过程有一定程度的理解。所以,我找到了一个例子,我相信它能帮我做这件事,但坦率地说,我不知道如何构造ftp路径?
这是完整的脚本(我在上找到的)
<?
// get FTP accessparameters
$host = "<URL of site>";
$user = "user@<URL of site>";
$pass = "<PASSWORD>";
$destDir= "www/uploads/files/";
$workDir= "/usr/local/temp"; // define this as perlocal system
// get temporary file namefor the uploaded file
$tmpName= basename($_FILES['ufile']['tmp_name']);
// copy uploaded file intocurrent directory
move_uploaded_file($_FILES['ufile']['tmp_name'], $workDir."/".$tmpName) or die("Cannot move uploaded file toworking directory");
// open connection
$conn= ftp_connect($host) or die ("Cannot initiate connection tohost");
// send access parameters
ftp_login($conn,$user, $pass) or die("Cannot login");
// perform file upload
$upload = ftp_put($conn, $destDir."/".$_FILES['ufile']['name'], $workDir."/".$tmpName, FTP_BINARY);
// check upload status
// display message
if (!$upload) {
echo "Cannotupload";
} else {
echo "Uploadcomplete";
}
// close the FTP stream
ftp_close($conn);
// delete local copy ofuploaded file
unlink($workDir."/".$tmpName) or die("Cannot delete uploaded filefrom working directory -- manual deletion recommended");
?>目前,它在“无法将上传的文件移动到工作目录”方面失败--因此我假设路径不正确。当这个特定的用户通过ftp连接时,他们的主目录是“file”。
我很感激你的建议。
在下面的答案
我让它起作用了。因为用户主目录是"file“,所以需要在这个目录中再加上两个名为”file“和"temp”的目录,我将上面的代码修改为:-
$destDir= "files";
$workDir= "temp";并找到一个要向后工作的ftp连接字符串的示例,以便代码生成正确的格式。当你知道怎么做的时候就容易了!
发布于 2011-07-22 12:31:49
我让它起作用了。因为用户主目录是"file“,所以需要在这个目录中再加上两个名为”file“和"temp”的目录,我将上面的代码修改为:-
$destDir= "files";
$workDir= "temp";并找到一个要向后工作的ftp连接字符串的示例,以便代码生成正确的格式。当你知道怎么做的时候就容易了!
https://stackoverflow.com/questions/6124857
复制相似问题