Using PHP to upload to secure FTP from website
Posted: Thu Sep 18, 2008 4:04 pm
Hey, I just want to thank everyone in advance for the help.
I need to use this code to upload from a website to a FTP with a username and password.
Depending on the user name and password the FTP with log the user into different directories.
The following code works with the website as far as moving the file to the directory.
I need help with how I would prompt the user for a username and password after they click the "Submit" button on the website.
Also, after the file is successfully uploaded how would I display a seperate "uploaded.html" page.
Thanks
HTML SECTION:
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
PHP SECTION:
<?php
$target = "upload/LocalUser/sunset/"; ->This directory could also be "upload/LocalUser/proofs/"
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok = 1;
$to = "******@gmail.com";
$subject = "File Submission";
$body = "A new file has been submitted via the website";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "PHP files cannot be uploaded.<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry, your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
mail($to,$subject,$body);
echo "An email has been sent to $to";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
I need to use this code to upload from a website to a FTP with a username and password.
Depending on the user name and password the FTP with log the user into different directories.
The following code works with the website as far as moving the file to the directory.
I need help with how I would prompt the user for a username and password after they click the "Submit" button on the website.
Also, after the file is successfully uploaded how would I display a seperate "uploaded.html" page.
Thanks
HTML SECTION:
<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
PHP SECTION:
<?php
$target = "upload/LocalUser/sunset/"; ->This directory could also be "upload/LocalUser/proofs/"
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok = 1;
$to = "******@gmail.com";
$subject = "File Submission";
$body = "A new file has been submitted via the website";
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "PHP files cannot be uploaded.<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry, your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
mail($to,$subject,$body);
echo "An email has been sent to $to";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>