PHP transfer script not appending username to file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Teonnyn
Forum Commoner
Posts: 58
Joined: Tue Dec 23, 2008 4:07 am

PHP transfer script not appending username to file

Post by Teonnyn »

I'm having a little bit of trouble with a transfer script. For some reason it doesn't seem to want to add the username of the person who uploaded it.

Code: Select all

<?PHP
$testname = $_COOKIE["flashcookie"];
$target_path = "";
$target_path = $target_path ."_" . $_COOKIE["flashcookie"] . $testname "-" . basename( $_FILES['Filedata']['name']);
 
rename($_FILES['Filedata']['tmp_name'], $target_path);
echo $testname;
?>
I've even tested it with an "echo", and it shows it's reading the $_COOKIE. This file is backend, and it recieves it's upload from Flash.
EDIT: The upload itself actually works, I just want to be able to identify who uploads what by adding the username to the file name.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: PHP transfer script not appending username to file

Post by susrisha »

Two things:
1.

Code: Select all

 
$_COOKIE["flashdata"] 
 
is used twice in the same line.

2.
you are trying to append two strings using a "." operator which i think is creating you the problem. But why are you appending the username twice ?

Code: Select all

 
$_COOKIE["flashdata"].$testname
 
well thats all i could find in it
Teonnyn
Forum Commoner
Posts: 58
Joined: Tue Dec 23, 2008 4:07 am

Re: PHP transfer script not appending username to file

Post by Teonnyn »

<?PHP
$testname = $_COOKIE["flashcookie"];
$target_path = "";
$target_path = $target_path . $testname . "-" . basename( $_FILES['Filedata']['name']);

move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path);
var_dump($target_path);
?>

Modified a little bit, but so far no luck with this.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP transfer script not appending username to file

Post by califdon »

Teonnyn wrote:

Code: Select all

<?PHP
$testname = $_COOKIE["flashcookie"];
$target_path = "";
$target_path = $target_path  . $testname . "-" . basename( $_FILES['Filedata']['name']);
 
move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path);
var_dump($target_path);
?>
Modified a little bit, but so far no luck with this.
In the future, please enclose PHP code in tags, as I have done immediately above. It makes it much easier to read and detect problems.

It's not clear to me what you are trying to do with this code. Why don't you explain what you expect to be in the cookie, what you want the filename to look like, and where you want the file to go? The above code really doesn't make much sense to me. You are using the same variables over and over for no purpose that I can see ($target_path). And you are using misleading variable names. The "target path" should not include the filename, but you are defining a variable named $target_path to be something (the user's name, perhaps?) plus a hyphen plus a filename. Unless I'm missing what you are trying to do, you are confused about what you are putting together in that string. Think it through and write it out on paper.
Teonnyn
Forum Commoner
Posts: 58
Joined: Tue Dec 23, 2008 4:07 am

Re: PHP transfer script not appending username to file

Post by Teonnyn »

Sorry about the tags, forgot those. Just as a note, I did not write the majority of this, but I have modified it.
The script is a simple file transfer that I'm using to load files from Flash and send them to the proper directory.
The cookie holds a username, and is used to display it from within Flash. Since the username cookie was already
in the system, I decided to use it again so that I could append it to the filename. The hyphen is ment to separate
the filename and the username added to the file.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP transfer script not appending username to file

Post by califdon »

I can't help you at all with Flash, but as far as the PHP goes, since you have removed the path from the original file specification (with the $target_path="";), it could be because the function move_uploaded_file() function requires a complete path specification.
Post Reply