This topic is locked

Renaming uploaded fiel

4/17/2024 7:17:12 PM
PHPRunner General questions
A
asawyer13 authorDevClub member

I would like to rename the uploaded file. I only allow one upload at a time.

The database date looks like this

[{"name":"TimeZones.txt","usrName":"TimeZones.txt","size":8139,"type":"text\/plain","searchStr":"TimeZones.txt,!:sStrEnd","FileName":"xxxxxx.jpg"}]

For now I am hardcoding xxxxxx.jpg as the file name I want to save on disk, but ultimately it will be something like 7RF3EWQv.jpg or whatever the proper extension is.

I just just be a bit off on the coding.

The field in the database is called FileName

Here is my code.

$fileArray = my_json_decode($values["FileName"]);

// rename files
for($i = 0; $i < count($fileArray); $i++)
{
$fileName = $fileArray[$i]["FileName"];
$newFileName = "xxxxxx.jpg";
rename($fileName, getabspath($newFileName));
$fileArray[$i]["FileName"] = $newFileName;
}

// update values of the field that stores file names
$values["FileName"] = my_json_encode($fileArray);

If someone wouldn't mind taking a look and tell me what I'm doing wrong I sure would appreciate it. The original code came from the PHPRunner help file.

Thanks again,
Alan

A
asawyer13 authorDevClub member 4/17/2024

Not sure I really need to do this. It looks like when the file is saved, it ends up with a unique name. Not perfect for what I want but I think it will work.