I am trying to create a script that allows a user to browse for a file using File Upload, and then the script should copy the file to our ftp server. It works great, but only for csvs or txt files. When trying to do other docs like pdf or xls, it does not seem to be transferring all of the data (the size of the final doc on the ftp site is slightly less than the size of the actual doc, as if it is not writing any EOF characters.) Anyone have any ideas why the following script would work for some types of files, but not others?
<?php
if ((($_FILES["file"]["type"] == "application/x-gzip-compressed")||($_FILES["file"]["type"] == "application/octet-stream")||($_FILES["file"]["type"] == "application/vnd.ms-excel")||($_FILES["file"]["type"] == "application/pdf")||($_FILES["file"]["type"] == "application/msword")))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "You have uploaded: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
}
}
else
{
echo "Invalid file. Files must be compressed, or in .txt,.csv,.pdf, Word, or Excel format. <br />";
}
$conn = ftp_connect("myftp.companyname.net") or die("Could not connect");
ftp_login($conn,$_POST["fsite"],$_POST["fpass"]);
ftp_pasv($conn, true);
set_time_limit(0);
ftp_put($conn,$_FILES["file"]["name"],$_FILES["file"]["tmp_name"],FTP_BINARY);
ftp_close($conn);
?>