Page 1 of 1
PHP transfer script not appending username to file
Posted: Thu Jan 15, 2009 7:39 pm
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.
Re: PHP transfer script not appending username to file
Posted: Fri Jan 16, 2009 12:16 am
by susrisha
Two things:
1.
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 ?
well thats all i could find in it
Re: PHP transfer script not appending username to file
Posted: Fri Jan 16, 2009 2:25 pm
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.
Re: PHP transfer script not appending username to file
Posted: Fri Jan 16, 2009 3:24 pm
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.
Re: PHP transfer script not appending username to file
Posted: Fri Jan 16, 2009 3:38 pm
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.
Re: PHP transfer script not appending username to file
Posted: Fri Jan 16, 2009 5:07 pm
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.