1

If I try to upload an image... It shows me the root folder with the size but it shows me only a white square... Not the picture with the resolution...

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

<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>

If I try to see the picture using the absolute link, it shows me only a white square... not the image. If I use FtpZilla to upload the image it works... So there must be a problem in my form.

Ivan
  • 34,531
  • 8
  • 55
  • 100
Stefan J.
  • 93
  • 9

1 Answers1

0

Once I had the same issue. Solved by adding this attribute to <input type="file">:

accept="image/jpeg"

You can add some more types if you wish. Hope that helps

  • i change and work partial,now is other problem doesnt have the resolution original, and is like 250 pixeli only... so is showing very ugly the picture – Stefan J. Aug 10 '16 at 13:49
  • @StefanJ., check the size with JS [like here](http://stackoverflow.com/questions/8903854/check-image-width-and-height-before-upload-with-javascript). Then check it in PHP with _getimagesize()_ and give me both results. Not sure what the problem could be –  Aug 10 '16 at 17:15
  • how can you give me a exemple? i am beginner... in codeing – Stefan J. Aug 10 '16 at 17:40
  • @StefanJ., if you are only a beginner, first read some books and documentation. Then improve your English, because it is really bad (don't want to insult you). Then search in the English part of the Net for the things I wrote before. And use your head, of course. I've already given you a link with JS example. As for getimagesize(), Google should be useful –  Aug 10 '16 at 18:06