PHP File Upload Fails


I am trying to do a FTP file upload which works fine on my localhost but on
my ISP server it fails. I can't seem to find where I can go to find the
specific cause of the failure. In both cases the file is being transmitted
to the same FTP server and using the same PHP script so it shouldn't be a
file size or login credentials problem. Could someone please help me out and
give me some ideas what is wrong.

I would really appreciate any help someone could provide as I've spent many
hours on this looking for answers. I've contacted my ISP and they've looked
at everything and also do not have an answer.

Thanks a lot,


Here is the PHP form and script I'm using:


<form enctype="multipart/form-data" action="fileupload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="300000" />
Choose a file to upload: <input name="uploadedfile" size="60" type="file" />
<input type="submit" name="continue" value="Continue" />


// set up basic connection
$ftp_server = "";
$conn_id = ftp_connect($ftp_server);

// login with username and password
$ftp_user_name = "XXX";
$ftp_user_pass = "XXX";
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// check connection
if ((!$conn_id) || (!$login_result)) {
$_SESSION['message_new']= "Attempted to connect to
$ftp_server for user $ftp_user_name has failed! ";
} else {
//echo "Connected to $ftp_server, for user $ftp_user_name";

// upload the file
$source_file = $_POST["uploadedfile"];

$basename = preg_replace( '/^.+[\\\\\\/]/', '', $source_file );
$filename = preg_replace( "/[^\w\.-]+/", "_", $basename );
$ShowID = $_SESSION['ShowID'];
$destination_file = $ShowID . "_" . $filename;

echo "source_file: $source_file <br>";
echo "filename : $filename <br>";
echo "destination_file: $destination_file<br>";

$upload = ftp_put($conn_id, $destination_file, $source_file,

// check upload status
if (!$upload) {
$_SESSION['message_new']= "FTP upload has failed; Contact

} else {
//echo "Uploaded $source_file to $ftp_server as
$_SESSION['message_new']="Uploaded $filename as

// close the FTP stream

# Now add the schedule name to the database
$connection = mysql_pconnect($host,$user,$password)
or die ("Couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("Couldn't select database.");

$query = "UPDATE ShowInfo SET ShowSchedule = '$destination_file'
WHERE ShowID=$ShowID";
$result = mysql_query($query)
or die("Problems encountered adding schedule information to
Query: $query <br> database: $database <br>");


Relevant Pages

  • Re: Single Logon
    ... upload command to upload files ... which implement those basic FTP verbs. ... |> components will retrieve a ServicePoint(which represent a connection to ... |> | private void DownloadFile(string strFilename, string strAddress, ...
  • Re: Silly query !
    ... The UpLoad Speed of a typical ADSL Connection is usually around about ... Connection Speeds - a Byte is normally 8 bits, ... Server?) ... WebSpace, using FTP? ...
  • Re: Can you use an FTP program with dial-up???
    ... > of them mention that they support FTP as opposed to BROWSER support. ... Yes you can use FTP upload to your web site if the host supports FTP, ... Since both methods involve use of the same connection from your ...
  • RE: strange upload trouble
    ... > The server is set to unlimited connections, ... > I start to upload a file. ... >, the server drops the connection and the ... FTP servers are not capable of holding more than one concurrent transfer to ...
  • Re: Not able to Ftp
    ... I was also looking at the missing challenge from the local security. ... Subject: Not able to Ftp ... 220 Connection will close if idle for more than 5 minutes. ... Search the archives at ...