douce1368 2018-05-03 11:05
浏览 80

用post发送文件,然后用ftp上传

This is a very basic question since I do not properly understand the underlying concepts of the different protocols. Please be indulgent.

I can upload files to my site with FTP using Filezilla. Now I'm developing a user interface for sending data to update a database and files (photos) to be saved in a directory. I send this data with POST (see here). I get the file, but cannot save it to the destination directory performing

move_uploaded_file($_FILES['PhotoToUpload']['tmp_name'],"../../Photos/".$file_name);

I think is because of permissions (currently 755). Since I can currently upload with Filezilla FTP (so I understand I have the permissions to do that),

my question is:

Is bad practice (or conceptually wrong) to take the temp file created after the POST and load it with a FTP code like the following (taken from here)?

<?php
$ftp_server = "myftp.co.uk";
$ftp_user_name = "myusername";
$ftp_user_pass = "mypass";
$destination_file = "../../Photos/";
$source_file = $_FILES['PhotoToUpload']['tmp_name'];

// set up basic connection
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id, true); 

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
    exit; 
} else {
    echo "Connected to $ftp_server, for user $ftp_user_name";
}

// upload the file
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 

// check upload status
if (!$upload) { 
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}

// close the FTP stream 
ftp_close($conn_id);
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 mmocr的训练错误,结果全为0
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀