我想将上传的文件移动到远程服务器,但ftp_put()
功能出错。错误是:
Warning: ftp_put(C:\xampp\tmp\php1296.tmp): failed to open stream: No such file or directory in C:\xampp\htdocs\intranet\admin_cuti\slip-gaji\insert-slip.php on line 65 There was a problem while uploading C:\xampp\tmp\php1296.tmp
我可以知道如何解决这个问题吗?
发现新错误:
Warning: ftp_put(): Prohibited file name:
/public_html/procurement/uploads/C:\xampp\tmp\php1A14.tmp in
C:\xampp\htdocs\intranet\admin_cuti\slip-gaji\insert-slip.php on line 69
There was a problem while uploading C:\xampp\tmp\php1A14.tmp
以下是我做的代码
更新正确的答案:
$temp_fpath = $_FILES['slip_gaji']['tmp_name'];
$fname = date('d-m-Y-H-i-s') . '-' . $_FILES['slip_gaji']['name'];
$ftp_server = "ftp.domain.com.my";
$ftp_user_name = 'myusername';
$ftp_user_pass = 'mypassword';
$file = $temp_fpath;
$remote_file = "/public_html/procurement/uploads/" . $fname;
// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// turn passive mode on
ftp_pasv($conn_id, true);
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
echo "successfully uploaded $file\n";
} else {
echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
答案 0 :(得分:1)
问题是 C:\ xampp \ tmp \ php1296.tmp 不存在。
/ tmp / php *文件通常在您提交Web表单时生成,与move_upload_file函数一起使用,并且一旦脚本结束就会被删除
要使用ftp_put,您必须知道文件的路径。