# Stuck, PHP upload with variables

**URL:** <https://forum.kirupa.com/t/stuck-php-upload-with-variables/257100>\
**Category:** Uncategorized\
**Created:** [April 10, 2008, 5:59am UTC](https://forum.kirupa.com/t/stuck-php-upload-with-variables/257100 "2008-04-10T05:59:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Doc1](https://avatars.discourse-cdn.com/v4/letter/d/87869e/32.png) [@Doc1](https://forum.kirupa.com/u/Doc1)\
**Post date:** [April 10, 2008, 5:59am UTC](https://forum.kirupa.com/t/stuck-php-upload-with-variables/257100/1 "2008-04-10T05:59:37Z")

</div>

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](http://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](http://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](http://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](http://www.server.com/upload/%24myFileName)

";  
[_]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]
