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.";
}
}
?>
Using PHP to upload to secure FTP from website
Moderator: General Moderators
Re: Using PHP to upload to secure FTP from website
You need to add " header (location:upload.html); " code inside following if condition and need to print message for file uploaded file successfully on upload.html
I have included sample code below pls have a try
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
mail($to,$subject,$body);
header (location:upload.html);
//echo "An email has been sent to $to";
}
I have included sample code below pls have a try
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
mail($to,$subject,$body);
header (location:upload.html);
//echo "An email has been sent to $to";
}
Re: Using PHP to upload to secure FTP from website
I think this will help with displaying the confirmation page, but I still need help making the FTP setup work.
Thanks for the help.
Morgan
Thanks for the help.
Morgan