Php ftp\u将文件上载到服务器时出错
我有一个HTML表单,用于将文件上载到服务器。我正在编写一个FTP客户端,目前运行良好,只是文件不会上传到服务器。我的表格如下:Php ftp\u将文件上载到服务器时出错,php,Php,我有一个HTML表单,用于将文件上载到服务器。我正在编写一个FTP客户端,目前运行良好,只是文件不会上传到服务器。我的表格如下: <form action='upload.php' id='upload'> <input type='file' name='file' /> <input name='file_name' placeholder='File Name' /> <input type='submit' value='
<form action='upload.php' id='upload'>
<input type='file' name='file' />
<input name='file_name' placeholder='File Name' />
<input type='submit' value='upload' />
</form>
这是我的php:
<?php
$ftp_connection = ftp_connect($_COOKIE['domain']);
if(@ftp_login($ftp_connection, $_COOKIE['username'], $_COOKIE['password'])) {
ftp_put($ftp_connection, $_REQUEST['file_name'], $_REQUEST['file']);
}
ftp_close($ftp_connection);
?>
还请注意,所有这些cookie都工作得很好,因为我使用它们登录FTP GUI。您的表单缺少上传文件时所需的
enctype=“multipart/form data”
另外,还需要一个POST方法
修改您的
及
如果正在调试,请不要使用@
来抑制错误/警告!Cookie存储纯文本密码,你确定吗?登录是100%确定的,因为正如我所说的,你必须登录才能进入GUI,它会将你带到文件上传器。我可以访问目录等东西,但上传将不起作用。是否需要完整的文件路径?如果是这样的话,我如何获得完整的文件路径,因为输入type='file'没有提供完整的文件路径。太棒了!但是,如何使用输入type='browse'获取需要上载到服务器的文件的完整路径?否,您需要在代码中设置自己的路径@turkey3@turkey3成功了吗?等等,服务器端文件和客户端大小的文件都需要一个完整的目录?
<form action='upload.php' id='upload' enctype='multipart/form-data' method='post'>
<?php
$ftp_server="";
$ftp_user_name="";
$ftp_user_pass="";
$file = "";//tobe uploaded
$remote_file = "";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} else {
echo "There was a problem while uploading $file\n";
exit;
}
// close the connection
ftp_close($conn_id);
?>
<?php
ftp_chdir($conn, '/www/site/');
ftp_put($conn,'file.html', 'c:/wamp/www/site/file.html', FTP_BINARY );
?>
<?PHP
$destination_path = "src/bin/";
//where you want to throw the file on the webserver (relative to your login dir)
$destination_file = $destination_path."img.jpg";
//This will create a full path with the file on the end for you to use, I like splitting the variables like this in case I need to use on on their own or if I'm dynamically creating new folders.
$file = $myFile['tmp_name'];
//Converts the array into a new string containing the path name on the server where your file is.
$upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);// upload the file
if (!$upload) {// check upload status
echo "FTP upload of $destination_file has failed!";
} else {
echo "Uploaded $file to $conn_id as $destination_file";
}
?>