通过FTP上传图片的表单不起作用,显示一个白色的正方形代替图片


form upload image by FTP doesn't work, shows a white square instead of the image

如果我尝试上传图像…它显示了根文件夹的大小,但它只显示了一个白色的正方形…不是分辨率高的照片……

upload.php

<?php require '../conx.php';  
session_start(); 
if(isset($_SESSION["userID"])){
    } else{
        header('Location: ../login.php');
        }
?>
<?php
$ftp_server = "ftp.xxxx.com";
$ftp_user_name = "xxxx@exemple.com";
$ftp_user_pass = "xxxxx";
$destination_file = "/public_html/lifestyle/imagini/" . $_FILES['file']['name'];
$source_file = $_FILES['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
if (ftp_put($conn_id, $destination_file, $source_file, FTP_ASCII)) {
 echo "successfully uploaded $destination_file'n";
    header('Location: administrator/admin_index_lifestyle.php');
} else {
 echo "There was a problem while uploading $destination_file'n";
}
// close the FTP stream 
ftp_close($conn_id);
?>

<form action="upload.php" enctype="multipart/form-data" method="post">
  <input name="file" type="file" />
  Upload foto in folderul lifestyle/imagini/ pentru ARTICOL
  <input name="submit" type="submit" value="Upload File in lifestyle" />
</form>

如果我尝试使用绝对链接查看图片,它只显示一个白色的正方形…不是图像。如果我使用FtpZilla上传图像,它可以工作…我的表单一定有问题

我曾经有过同样的问题。通过将此属性添加到<input type="file">:

解决
accept="image/jpeg"

如果你愿意,你可以添加更多的类型。希望对大家有所帮助