Skip to content
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

File uploader renames with other ext #81

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fd3c345
modified composer.json
Joe04 Apr 29, 2014
f01c090
fixed composer.json
Joe04 Apr 29, 2014
a0c7946
reverted changes on composer.json
Joe04 Apr 29, 2014
a707ec8
added a test for outputing the errors
Joe04 Apr 29, 2014
62e0b08
display the error in the console
Joe04 Apr 29, 2014
ec75a3d
append error as a div
Joe04 Apr 29, 2014
c30977c
display the message in a box and make it fadeout after 3 seconds
Joe04 Apr 29, 2014
9d8edd4
fixed the appearence of the error message so it can be translated
Joe04 Apr 30, 2014
bd002d7
better exception if rsync failed
Metabor Feb 2, 2015
fbb378e
Strip special characters for UploadHandler
Jul 28, 2015
67e522f
Merge pull request #1 from christophebeling/master
Jul 28, 2015
0bcdf80
Fix file upload issue
Jul 30, 2015
834ccea
Merge pull request #3 from christophebeling/master
Jul 30, 2015
71fc11f
check for basename to exist for any of the allowed extensions in orde…
Jun 15, 2016
bf6e157
added tests
Jun 15, 2016
f33d50b
added docblock
Jun 15, 2016
9f29934
added test
Jun 15, 2016
669849c
only return allowed extensions, not empty ones
Jun 15, 2016
da634c9
Merge pull request #4 from kyto-gmbh/check-for-basename-to-not-exist
llissssss Jun 16, 2016
356cec2
Escape thumbnail preview url for existing images to be same as delete…
AnastasiosDrosos Mar 17, 2017
abe06f0
Merge pull request #5 from kyto-gmbh/bugfix/escape-thumbnail-url
luksurious Mar 20, 2017
fb13977
AnastasiosDrosos Mar 27, 2017
abc2722
AnastasiosDrosos Mar 27, 2017
ec1aefc
Merge pull request #6 from kyto-gmbh/bugfix/fix-image-url
drososanastasios Mar 27, 2017
59c3e30
handle UTF-8 filenames the right way
Jun 1, 2017
8564859
File name with different extion renaming issue : Revert to Original c…
Feb 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added tests
  • Loading branch information
Albert Casadessús committed Jun 15, 2016
commit bf6e157be87f2a358a4d8f1eeea39f6f63e5edb1
11 changes: 6 additions & 5 deletions BlueImp/UploadHandler.php
Original file line number Diff line number Diff line change
@@ -265,17 +265,18 @@ protected function trim_file_name($file_name, $type, $index) {
preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
$file_name .= '.'.$matches[1];
}
$acceptedFileTypesRegex = $this->options['accept_file_types'];
if ($this->options['discard_aborted_uploads']) {
while($this->is_basename_existing($this->options['upload_dir'], $file_name)) {
while($this->is_basename_existing($this->options['upload_dir'], $file_name, $acceptedFileTypesRegex)) {
$file_name = $this->upcount_name($file_name);
}
}
return $file_name;
}

protected function is_basename_existing($dir, $fileName)
protected function is_basename_existing($dir, $fileName, $acceptedFileTypesRegex)
{
$extensions = $this->get_accepted_extensions_from_options_regex($this->options['accept_file_types']);
$extensions = $this->get_accepted_extensions_from_options_regex($acceptedFileTypesRegex);
$pathParts = pathinfo($fileName);
$nameWithoutExtension = $pathParts['filename'];
foreach ($extensions as $extension) {
@@ -286,9 +287,9 @@ protected function is_basename_existing($dir, $fileName)
return false;
}

protected function get_accepted_extensions_from_options_regex($regex)
protected function get_accepted_extensions_from_options_regex($acceptedFileTypesRegex)
{
preg_match_all('(\.[a-z]+)', $regex, $matches);
preg_match_all('(\.[a-z]+)', $acceptedFileTypesRegex, $matches);
$extensions = $matches[0];
$extensions[] = '';

21 changes: 18 additions & 3 deletions Test/BlueImp/UploadHandlerTest.php
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
*/
class UploadHandlerTest extends \PHPUnit_Framework_TestCase
{

/**
*
*/
@@ -31,6 +30,22 @@ public function testGetExtensionsFromRegex()
$this->assertEquals('', $extensions[5]);
}

/**
*
*/
public function testIsBasenameExisting()
{
$regex = '/(\.jpg|\.jpeg|\.gif|\.png|\.pdf)$/i';
$dir = __DIR__ . '/../upload-dir/';
$uploadHandler = new UploadHandlerMock();

$result = $uploadHandler->is_basename_existing_wrapper($dir, 'test.png', $regex);
$this->assertTrue($result);

$result = $uploadHandler->is_basename_existing_wrapper($dir, 'I-do-not-exist.jpg', $regex);
$this->assertFalse($result);
}

/**
*
*/
@@ -65,9 +80,9 @@ public function get_accepted_extensions_from_options_regex_wrapper($regex)
return $this->get_accepted_extensions_from_options_regex($regex);
}

public function is_basename_existing_wrapper()
public function is_basename_existing_wrapper($directory, $filename, $regex)
{
return $this->is_basename_existing();
return $this->is_basename_existing($directory, $filename, $regex);
}
}

Empty file added Test/upload-dir/test.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.