Jump to content

Need help with PHP FTP Script


samis

Recommended Posts

I click submut but it's still not upload the image or sending the email.I am just at my end because I can't get it to work.

All I need to do is upload file to an FTP account and then send and email.

That's it, I thought it would be simple

Here is the code:

<?php 
function uploadFileFTP($FileName) { 
    //connect to the ftp server  
    $conn_id = ftp_connect(FTP_SERVER_ADDRESS);  
     
    // login with username and password  
    $login_result = ftp_login($ftp.mysite.com, tradeshow, Exhibits);  
    ftp_pasv($conn_id);  


// get posted data into local variables 
    	$email = Trim(stripslashes($_POST['email']));
$EmailTo = "[email protected]"; 
    	$Subject = "New File Uploads"; 
    	$FristName = Trim(stripslashes($_POST['FristName']));  
    	$LastName = Trim(stripslashes($_POST['LastName']));  
    	$email = Trim(stripslashes($_POST['email']));  
    	$CompanyName = Trim(stripslashes($_POST['CompanyName'])); 
$phone = Trim(stripslashes($_POST['phone'])); 
$comments = Trim(stripslashes($_POST['comments'])); 
    	$IP=$_SERVER['REMOTE_ADDR'];  

//skip these two steps if you dont want to change the working directory 
    ftp_chdir($conn_id, "wwwroot"); 
    ftp_chdir($conn_id, "my_folder"); 





// prepare email body text
$Body = "";
$Body .= "FristName: ";
$Body .= $FristName;
$Body .= "\n";
$Body .= "LastName: ";
$Body .= $LastName;
$Body .= "\n";
$Body .= "email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "CompanyName: ";
$Body .= $CompanyName;
$Body .= "\n";
        $Body .= "phone: ";
$Body .= $phone;
$Body .= "\n";
        $Body .= "comments: ";
$Body .= $comments;
        $Body .= "\n";
        $Body .= "Sender Ip Address: ";
$Body .= $IP;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$email>");

    // upload the files 
    $upload = ftp_put($conn_id, $FileName, $source_file, FTP_Binary); 
          
if (!$upload) { 
        echo "error=FTP upload has failed!";
        ftp_close($conn_id); 
        return false; 
    } else { 
        ftp_close($conn_id); 
        return $FileName; 
    } 
}  
// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thankyou.html\">";
}
?>

 

Heres the HTML Code:

<form id="upload" name="upload" method="post" action="graphics_exec2.php">



<p>First Name<br>       
              <input type="text" maxlength="60" size="60" value="" name="FristName" id="FristName"/>
<p>Last Name<br>       
              <input type="text" maxlength="60" size="60" value="" name="LastName" id="LastName"/>
<p>Company Name<br>       
              <input type="text" maxlength="60" size="60" value="" name="CompanyName" id="CompanyName"/>

<p>Email<br>       
              <input type="text" maxlength="60" size="60" value="" name="email" id="email"/>
<p>Phone<br>       
              <input type="text" maxlength="60" size="60" value="" name="phone" id="phone"/><br><br>

<br>
<label for="file"></label><input type="file" name="Filename" id="file" /><br>
<label for="file"></label><input type="file" name="Filename" id="file1" /> <br>
<label for="file"></label><input type="file" name="Filename" id="file2" /> <br>



<br><p>If you wish, please use this space to tell us anything else about your files:</p>
             
<textarea id="Comments" rows="6" cols="60" name="comments"/></textarea>


<input type="submit" value="submit" name="submit"/>
              
              <input type="reset" id="FormsButton62" value="Reset" name="FormsButton2"/>
              

</div></form>

 

 

Link to comment
https://forums.phpfreaks.com/topic/158761-need-help-with-php-ftp-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.