-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moved uploaded files doesn't retain new filename. #839
Comments
We could change from this public function move(string $targetPath, string $name = null, bool $overwrite = false)
{
.......................
$destination = $overwrite ? $this->getDestination($targetPath . $name) : $targetPath . $name;
.......................
// Success, so store our new information
$this->path = $targetPath;
$this->name = $name;
$this->hasMoved = true;
return true;
} to this public function move(string $targetPath, string $name = null, bool $overwrite = false)
{
.......................
//Flip ternary operation
$destination = !$overwrite ? $this->getDestination($targetPath . $name) : $targetPath . $name;
.......................
//**Reparse the new file from the new destination, works on my end**
$newFile = pathinfo( $destination );
$this->path = $newFile['dirname'];
$this->name = $newFile['basename'];
$this->hasMoved = true;
return true;
} |
For file name we do need to save the name after determining the destination since the docs state:
I would update the filename with As for overwriting and flipping the ternary: it would have been nice if you would have given the logic for why you wanted it flipped :) Took me a second, but yes, you're correct that should be modified otherwise overwriting won't actually work. |
After more testing I did read the docs and saw that it returns a new instance of the file. So I ended up not digging into a fix since I am still developing. As for the ternary, I assumed since I was looking at it for an hour that other people would understand xD. But you're right, I didn't document the logic well at all. Edit: my proposed fix above is completely useless and should be ignored |
Fix Issue #839 - Moved uploaded files doesn't retain new filename or overwrite
Once an uploaded file has moved and has an integer appended on the end for allowing multiple of the same files... the file object does not retain the new filename. In the function move() it calls getDestination() which can create a new filename and return a new path to move to. But the new filename does not get saved, it is used to move the file, and then gone. @lonnieezell I don't really know how you'd want to address this, other than reparsing the new path from getDestination... Just seems redundant.
Also I think this ternary operation needs flippe.
The text was updated successfully, but these errors were encountered: