Hello,
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,
Vic
Here is the PHP form and script I'm using:
Form:
<form enctype="multip art/form-data" action="fileupl oad.php" method="POST">
<input type="hidden" name="MAX_FILE_ SIZE" value="300000" />
Choose a file to upload: <input name="uploadedf ile" size="60" type="file" />
<input type="submit" name="continue" value="Continue " />
</form>
PHP:
// set up basic connection
$ftp_server = "ftp.showmyhors e.com";
$conn_id = ftp_connect($ft p_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! ";
break;
} else {
//echo "Connected to $ftp_server, for user $ftp_user_name" ;
}
// upload the file
$source_file = $_POST["uploadedfi le"];
$basename = preg_replace( '/^.+[\\\\\\/]/', '', $source_file );
$filename = preg_replace( "/[^\w\.-]+/", "_", $basename );
$ShowID = $_SESSION['ShowID'];
$destination_fi le = $ShowID . "_" . $filename;
echo "source_fil e: $source_file <br>";
echo "filename : $filename <br>";
echo "destination_fi le: $destination_fi le<br>";
$upload = ftp_put($conn_i d, $destination_fi le, $source_file,
FTP_BINARY);
// check upload status
if (!$upload) {
$_SESSION['message_new']= "FTP upload has failed; Contact
support@showmyh orse.com!";
} else {
//echo "Uploaded $source_file to $ftp_server as
$destination_fi le";
$_SESSION['message_new']="Uploaded $filename as
$destination_fi le";
}
// close the FTP stream
ftp_close($conn _id);
# Now add the schedule name to the database
$connection = mysql_pconnect( $host,$user,$pa ssword)
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_f ile'
WHERE ShowID=$ShowID" ;
$result = mysql_query($qu ery)
or die("Problems encountered adding schedule information to
database
Query: $query <brdatabase: $database <br>");
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,
Vic
Here is the PHP form and script I'm using:
Form:
<form enctype="multip art/form-data" action="fileupl oad.php" method="POST">
<input type="hidden" name="MAX_FILE_ SIZE" value="300000" />
Choose a file to upload: <input name="uploadedf ile" size="60" type="file" />
<input type="submit" name="continue" value="Continue " />
</form>
PHP:
// set up basic connection
$ftp_server = "ftp.showmyhors e.com";
$conn_id = ftp_connect($ft p_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! ";
break;
} else {
//echo "Connected to $ftp_server, for user $ftp_user_name" ;
}
// upload the file
$source_file = $_POST["uploadedfi le"];
$basename = preg_replace( '/^.+[\\\\\\/]/', '', $source_file );
$filename = preg_replace( "/[^\w\.-]+/", "_", $basename );
$ShowID = $_SESSION['ShowID'];
$destination_fi le = $ShowID . "_" . $filename;
echo "source_fil e: $source_file <br>";
echo "filename : $filename <br>";
echo "destination_fi le: $destination_fi le<br>";
$upload = ftp_put($conn_i d, $destination_fi le, $source_file,
FTP_BINARY);
// check upload status
if (!$upload) {
$_SESSION['message_new']= "FTP upload has failed; Contact
support@showmyh orse.com!";
} else {
//echo "Uploaded $source_file to $ftp_server as
$destination_fi le";
$_SESSION['message_new']="Uploaded $filename as
$destination_fi le";
}
// close the FTP stream
ftp_close($conn _id);
# Now add the schedule name to the database
$connection = mysql_pconnect( $host,$user,$pa ssword)
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_f ile'
WHERE ShowID=$ShowID" ;
$result = mysql_query($qu ery)
or die("Problems encountered adding schedule information to
database
Query: $query <brdatabase: $database <br>");
Comment