我的图像上传有问题,它不起作用。。。给我这个错误
已连接到ftp.example.com,用于用户exemple@exemple.com警告:ftp_put():中的文件名不能为空/home/user/public_html/foto-test.php在第26行FTP上传失败!
<?php
$ftp_server = "ftp.xxxx.com";
$ftp_user_name = "xxxx@xxxx.com";
$ftp_user_pass = "xxxxxxx";
$folder = "/public_html/images";
$destination_file = $folder . $_FILES['file']['name'];
$source_file = $_FILE['file']['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); //line 26
// 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);
?>
我试图更改$folder目标,但它给了我一些错误。。。
在这里查看答案PHP FTP上传错误:警告:FTP_put()[function.FTP put]:文件名在中不能为空
此外,你的目的地路径应该在的末尾有一个斜线
$folder = "/public_html/images";
$destination_file = $folder . $_FILES['file']['name'];
将其更改为
$folder = "/public_html/images/";
$destination_file = $folder . $_FILES['file']['name'];
因此,很明显,您上传的任何(图像)都将进入图像文件夹,而不是"图像+SomeName"文件夹