Forum Moderators: coopster

Message Too Old, No Replies

filename of uploaded file is not the original name

         

12inch

3:44 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



With the following code I upload an image:

copy($HTTP_POST_FILES['userfile']['tmp_name'], "./var/www/html/upload/." .$HTTP_POST_FILES['userfile']['name'])
or die ("Copying file failed! ");

Then I put the original filename of the image in a MySQL database. But I get only the tmpname, like: /tmp/phpcRkEDa or /tmp/phpgeZl3A instead of picture1.jpg

Can anyone tell me how to fix this problem?
Thanx!

Anand

justageek

6:32 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use move_uploaded_file(). Works perfect.

JAG

dreamcatcher

6:42 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Me too. Maybe try:

$temp = $_FILES[userfile][tmp_name];
$name = $_FILES[userfile][name];

move_uploaded_file($temp, "./var/www/html/upload/." .$name)or die ("Copying file failed! ");

:)

12inch

8:37 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



I have tried it with move_uploaded_file. The file is uploaded, with the original filename, but not in the MySQL database.

I think the problem lies somewhere in this code:
(You can choose an image from a form (browse) and then submit the form.)

if ($HTTP_POST_VARS['submituser'] == "SUBMIT DATA") {
$sql = "INSERT INTO Users (foto) VALUES ('$userfile')";
if (@mysql_query($sql)) {
echo("<p>Your userdata has been added.</p>");
} else {
echo("<p>Error adding submitted userdata: " .mysql_error() . "</p>");
}
}

I think the value of $userfile is the tempname. I don't know why.

dreamcatcher

8:41 pm on Sep 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably a question for the more experienced programmers. How about trying:

if ($HTTP_POST_VARS['submituser'] == "SUBMIT DATA")

$name = $_FILES[userfile][name];

{

$sql = "INSERT INTO Users (foto) VALUES ('$name')";
if (@mysql_query($sql)
{

echo("<p>Your userdata has been added.</p>");

}

else

{

echo("<p>Error adding submitted userdata: " .mysql_error() . "</p>");

}

}

:)

12inch

8:46 pm on Sep 15, 2003 (gmt 0)

10+ Year Member



YESSSSSSSSSSSSSSSS, that did it ...
Thank you very much!

Anand

dreamcatcher

9:11 am on Sep 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You`re welcome!

:)