Basically, I have an FTP/PHP upload form that requests a users name.
I want to be able to have the files that get uploaded ($myFileName), sent to a subdirectory in the users name ($whoareyou).
so if your name was “bob” and you uploaded “bob.jpg”
I want your file to be sent to:
…/bob/bob.jpg
This is probably really simple, but I’ve spent two days on it… I’m going cross-eyed.
I thought it was on line 7 of PHP, but I’m getting the syntax wrong.
PHP CODE:[LIST=1]
[]<?php
[] if(isset($_POST[‘SubmitFile’])){
[] $myFile = $_FILES[‘txt_file’];
[] $file = $myFile[‘tmp_name’];
[] $myFileName = basename($_FILES[‘txt_file’][‘name’]);
[] $whoareyou = $_POST[“whatsyourname”];
[] $destination_file = “httpdocs/upload/”.$myFileName;
[] $ftp_server = “server.com”;
[] $ftp_user_name = “username”;
[] $ftp_user_pass = “password”;
[] $conn_id = ftp_connect($ftp_server);
[] $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("<h2>You do not have access to this ftp server!</h2>");
[] $upload = ftp_put($conn_id, $destination_file, $file, FTP_BINARY);
[] ftp_close($conn_id);
[] }
[]?>[/LIST]HTML CODE:[LIST=1]
[]<form enctype=“multipart/form-data” action="<?php echo $_SERVER[‘PHP_SELF’];?>" method=“POST”>
[]<?php
[]if (!$upload) { // check upload status
[] echo “<h2>You are connected to server.com!</h2><br />”;
[] } else {
[] echo “<h2>$myFileName successfully uploaded!</h2><br />”;
[]$sendTo = "name@email.com";
[]$subject = “A file has been uploaded to server.com”;
[]$headers = "From: " . $_POST[“name”];
[]$headers .= “<” . $_POST[“email”] . ">
";
[]$headers .= "Reply-To: " . $_POST[“email”] . "
";
[]$headers .= "Return-Path: " . $_POST[“email”];
[*]$message .= "$whoareyou uploaded $myFileName to http://www.server.com/upload/$myFileName
";
[]mail($sendTo, $subject, $message, $headers);
[] }
[]?>
[]Please choose a file: <input name=“txt_file” type=“file” id=“txt_file” tabindex=“1” size=“55” onChange=“txt_fileName.value=txt_file.value” />
[]<input name=“txt_fileName” type=“hidden” id=“txt_fileName” tabindex=“99” size=“1” />
[]<br /><br />
[]What’s Your Name?<input type=“text” name=“whatsyourname” size=“20”>
[]<input type=“submit” name=“SubmitFile” value=“Upload File” accesskey=“ENTER” tabindex=“2” />
[*]</form>[/LIST]