Divyansh94531
Divyansh94531

Reputation: 7

Unable to connect to uploadify using HTML and PHP

<html>[enter image description here][1]
  <body>
    <form enctype="multipart/form-data" action="upload_file.php" method="POST">
      <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
      Choose a file to upload: <input name="uploadedfile" type="file" /><br />
      <input type="submit" value="Upload File" />
    </form>
    
    <?php

$ftp_server = "94.23.x.xxx";
$ftp_username   = "anxxxsdx";
$ftp_password   =  "6Zxxxxx65exx";

// setup of connection
$conn_id = ftp_connect($ftp_server) or die("could not connect to $ftp_server");

// login
if (@ftp_login($conn_id, $ftp_username, $ftp_password))
{
  echo "conectd as $ftp_username@$ftp_server\n";
}
else
{
  echo "could not connect as $ftp_username\n";
}

$file = $_FILES["uploadedfile"]["name"];
$remote_file_path = "/JustForTest".$file;
ftp_put($conn_id, $remote_file_path, $_FILES["uploadedfile"]["tmp_name"],
        FTP_ASCII);
ftp_close($conn_id);
echo "\n\nconnection closed";

?>
    
  </body>
</html>

And here is the error message while compiling : Select image to upload: No file chosen Couldn't connect to 94.23.x.xxx

Any inputs I just tried to run this by pasting the entire code on notepad and saving it as upload.php extension.

***I am new to php and uploadify integration. Please help.

I have tried all most all the possible way. Please suggest.

Upvotes: -2

Views: 46

Answers (1)

Oris Sin
Oris Sin

Reputation: 1234

First of all, do a check on your $_FILES variable if you are actually receiving anything from the client side.

I would recommend you also to do one more conditional statement which checks if the tempFile you created, has been moved to your target path. If not, then probably you are facing some issue with your connection to the FTP.

if (!empty($_FILES)) {
   $file = $_FILES["uploadedfile"]["name"];
   $tempFile = $_FILES['uploadedfile']['tmp_name'];                          
 
   $targetPath = $_SERVER['DOCUMENT_ROOT'] . "/JustForTest". $file;  
   $targetFile =  str_replace('//','/', $targetPath) . $_FILES['uploadedfile']['name']; 
   ftp_put($conn_id, $targetPath, $_FILES["uploadedfile"]["tmp_name"], FTP_ASCII);
  ftp_close($conn_id);

  if(move_uploaded_file($tempFile, $targetFile)){  // string of temporary name file, the destination path of the moved file                    
     echo true; // you can echo something in here to try and see if your code executes until that point
   }else{
    echo false;
   }
     
}

Upvotes: 0

Related Questions