ftp upload by php?
this is my code to upload files to another server.
but it doesn't work, why?
if i fill in the right things it doesn't work
[PHP]<form name="form1" enctype="multipart/form-data" method="post" action="<?php $PHP_SELF ?>">
<input type="file" name="source_file">
<br>
<input type="submit" name="submit" value="Submit">
</form><br />
<?php
error_reporting(E_ALL);
if(isset($_POST['submit'])) {
$size = $_FILES['source_file']['size'] / 1024 / 1024;
$size = round($size, 2);
echo 'Het volgende bestand wordt geüpload:<br />
Naam: ' . $_FILES['source_file']['name'] .
'<br />Grootte: ' . $size .
' MB<br /><b>tmp_name:</b> ' . $_FILES['source_file']['tmp_name'] . '<br />
de upload wordt verwerkt...<br />';
//variabelen definiëren
$ftp_server = "ftp.teun95.sixserve.com";
$ftp_user_name = "admin@teun95.sixserve.com";
$ftp_user_pass = "hoedje11";
$source_file = $_FILES['source_file']['tmp_name'];
$destination_file = $_FILES['source_file']['name'];
// maak een basis connectie aan
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id,TRUE);
// meldt je aan met een gebruikersnaam en wachtwoord
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// controleer de verbinding
if ((!$conn_id) || (!$login_result)) {
echo "FTP connectie is mislukt!<br />";
echo "Probeerde naar $ftp_server te verbinden met de gebruiker $ftp_user_name<br />";
exit;
} else {
echo "Verbonden met $ftp_server, als gebruiker $ftp_user_name<br />";
}
// upload een bestand
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// controleer de upload status
if (!$upload) {
echo "FTP upload is mislukt!<br />";
} else {
echo "Geupload: $source_file naar $ftp_server als $destination_file<br />";
}
// sluit de FTP stream
ftp_close($conn_id);
if($conn_id == "1" && $login_result == "1" && $upload == "1") echo '<br><b>Operatie succesvol</b><br /><br />';
else echo '<b>Mislukt!</b><br /><br />';
}
?>
[/PHP]
but it doesn't work, why?
if i fill in the right things it doesn't work
[PHP]<form name="form1" enctype="multipart/form-data" method="post" action="<?php $PHP_SELF ?>">
<input type="file" name="source_file">
<br>
<input type="submit" name="submit" value="Submit">
</form><br />
<?php
error_reporting(E_ALL);
if(isset($_POST['submit'])) {
$size = $_FILES['source_file']['size'] / 1024 / 1024;
$size = round($size, 2);
echo 'Het volgende bestand wordt geüpload:<br />
Naam: ' . $_FILES['source_file']['name'] .
'<br />Grootte: ' . $size .
' MB<br /><b>tmp_name:</b> ' . $_FILES['source_file']['tmp_name'] . '<br />
de upload wordt verwerkt...<br />';
//variabelen definiëren
$ftp_server = "ftp.teun95.sixserve.com";
$ftp_user_name = "admin@teun95.sixserve.com";
$ftp_user_pass = "hoedje11";
$source_file = $_FILES['source_file']['tmp_name'];
$destination_file = $_FILES['source_file']['name'];
// maak een basis connectie aan
$conn_id = ftp_connect($ftp_server);
ftp_pasv($conn_id,TRUE);
// meldt je aan met een gebruikersnaam en wachtwoord
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// controleer de verbinding
if ((!$conn_id) || (!$login_result)) {
echo "FTP connectie is mislukt!<br />";
echo "Probeerde naar $ftp_server te verbinden met de gebruiker $ftp_user_name<br />";
exit;
} else {
echo "Verbonden met $ftp_server, als gebruiker $ftp_user_name<br />";
}
// upload een bestand
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// controleer de upload status
if (!$upload) {
echo "FTP upload is mislukt!<br />";
} else {
echo "Geupload: $source_file naar $ftp_server als $destination_file<br />";
}
// sluit de FTP stream
ftp_close($conn_id);
if($conn_id == "1" && $login_result == "1" && $upload == "1") echo '<br><b>Operatie succesvol</b><br /><br />';
else echo '<b>Mislukt!</b><br /><br />';
}
?>
[/PHP]