I am getting a parse error on line 29 of this code. Line 29 of the code is the else statment. It is this part:
//try to change directory to upload directory once connection is made
if( ftp_chdir($conn_id, "incoming") );
{
print("Current directory is now: " .ftp_pwd($conn_id) . "<br />");
}
else
{
print("Couldn't change directory <br />");
}
This script accepts a file via a web page form and uploads it to my ftp site.
I am not sure if I used the superglobal array $_FILES correctly. I am including the html for completeness. Any assistance is greatly appreciated as I can learn much from this script. I also commented it for the benefit of other newbies like me.
Have a blessed day... Hope to hear from someone.
---uploader_ver2.html---
<form action="uploader_ver2.php" method="post"
enctype="multipart/form-data">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="userfile" size="50">
<br/>
<input type="submit" value="Upload thy file...">
</form>
<html><head><title></title></head><body><ul>
<!-- Put together by christianguy for the benefit of others -->
<?php
if ( ($_FILES['userfile']['size'] !== 0) && ($_FILES['userfile']['tmp_file'] != "") );
{
//delcare which server, username, & password to use
$ftp_server = "ftp.mydomain.net";
$ftp_user = "anonymous@mydomain.net";
$ftp_pass = "anonymous@mydomain.net";
//setup a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to" .$ftp_server);
//try to login to ftp server & display the result of that attempt
if( @ftp_login($conn_id, $ftp_user, $ftp_pass) )
{
print("Connected <br />");
}
else
{
print("Couldn't connect <br />");
}
//try to change directory to upload directory once connection is made
if( ftp_chdir($conn_id, "incoming") );
{
print("Current directory is now: " .ftp_pwd($conn_id) . "<br />");
}
else
{
print("Couldn't change directory <br />");
}
//the temporary filename of the file in which the upload file was stored on the server
$file = $_FILES['userfile']['tmp_name'];
//the original name of the file
$remote_file = $_FILES['userfile']['name'];
/* The "ASCII" option will allow you to very rapidly transfer text-only files that have been saved in ASCII format. (Compression is used to speed the transfer.)
The "Binary" function will transfer all other files (images, applications, word processor documents).
It is important to note that the "ASCII" option will not transfer files other than ASCII text sucessfully. Files which should be transferred in binary mode but are transferred in ASCII will be useless.*/
if ( ftp_put($conn_id, $remote_file, $file, FTP_BINARY) )
{
/*PHP automatically creates three additional variables for HTML file inputs that store information about the uploaded file. Their names are based upon the name specified as the input name suffixed with _name, _size, _type. So if the value assigned to the input's name attriute was userfile, PHP would create these four variables.*/
/*The <li> element defines a list item. The element must be contained within DIR, MENU, OL or UL.*/
print ("Successfully uploaded" .$remote_file . "<br />");
print ("<li> Sent:" .$userfile_name . "<br />");
print ("<li> Size:" .$userfile_size . "<br />");
print ("<li> Type:" .$userfile_type . "<br />");
}
else //if it doesn't work, then do this :-(
{
print ("There was a problem while uploading" . " " .$remote_file . "<br />");
}
//close the connection to the ftp server
ftp_close($conn_id);
}
else
{
die("No file specified");
}
?>
</ul>
</body>
</html>
//try to change directory to upload directory once connection is made
🙂 🙂