Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

change file name on upload in PHP

Participant ,
Jun 25, 2010 Jun 25, 2010

HI Folks,

I am trying to rename a file uploaded in a form using this.

But nothing happens. I can't figure out why but I'm sure you guys will see the problem straight away.

if(isset($_FILES['logo']['name']))

{$_FILES['logo']['name']=("".$row_rs_member['id']."jpg");}

Any ideas?

Dave

TOPICS
Server side applications
4.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 25, 2010 Jun 25, 2010

Take a look at move_uploaded_file function:

http://php.net/manual/en/function.move-uploaded-file.php

In your case, something like this should work:

$filename = $row_rs_member['id'] . ".jpg";

$filepath = "/home/username/html/files/"; // CHANGE THIS WITH YOUR OWN PATH...

move_uploaded_file($_FILES['logo']['tmp_name'], $filepath . $filename);

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 25, 2010 Jun 25, 2010

Thanks but I'm confused.

I don't want to move the file.

It's aldready being uploaded to the right folder, just with the existing name. `so if I can just change the filename before it's uploaded everything will work perfectly.

Isn't there just a straightforward way of renaming the file?

Dave

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 25, 2010 Jun 25, 2010
LATEST

Yes there is:

http://www.php.net/manual/en/function.rename.php

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines