Skip to content

Commit a8a9ef8

Browse files
committed
Add duplicate handling and CHANGELOG.
1 parent c3ea2cd commit a8a9ef8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
This project adheres to [Semantic Versioning](http://semver.org/).
4+
5+
## [Unreleased]
6+
### Added
7+
- This CHANGELOG file.
8+
9+
### Changed
10+
- Handle duplicate files in the same way as the Python implementation, adding
11+
the new 409 response code from API v2.
12+
13+
## 1.0.0-rc.1 - 2015-11-03
14+
### Added
15+
- The server implementation all packed in a single file.
16+
- Documentation to help people get started.
17+
18+
[Unreleased]: https://github.com/PhotoBackup/server-php/compare/v1.0.0-rc.1...HEAD

index.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@
127127
$filename = preg_replace('@[^0-9a-z._-]@i', '', $filename);
128128
$target = $MediaRoot . '/' . $filename;
129129

130+
/**
131+
* If a file with the same name and size exists, treat the new upload as a
132+
* duplicate and exit.
133+
*/
134+
if (
135+
file_exists($target) &&
136+
filesize() === $_POST['filesize']
137+
) {
138+
header($protocol . ' 409 Conflict');
139+
exit();
140+
}
141+
130142
/**
131143
* Move the uploaded file into the target directory. If anything did not work,
132144
* exit with HTTP code 500.

0 commit comments

Comments
 (0)