mirror of
https://github.com/processwire/processwire.git
synced 2025-08-18 12:31:17 +02:00
Fix issue processwire/processwire-issues#462 solution for files using arabic filenames
This commit is contained in:
@@ -406,6 +406,7 @@ class WireUpload extends Wire {
|
||||
if($this->lowercase) $value = function_exists('mb_strtolower') ? mb_strtolower($value) : strtolower($value);
|
||||
$value = $this->wire('sanitizer')->filename($value, Sanitizer::translate);
|
||||
$value = trim($value, "_");
|
||||
if(!strlen($value)) return false;
|
||||
|
||||
$p = pathinfo($value);
|
||||
if(!isset($p['extension'])) return false;
|
||||
@@ -434,11 +435,30 @@ class WireUpload extends Wire {
|
||||
protected function saveUpload($tmp_name, $filename, $ajax = false) {
|
||||
|
||||
if(!$this->checkDestinationPath()) return false;
|
||||
|
||||
$success = false;
|
||||
$error = '';
|
||||
$filename = $this->getTargetFilename($filename);
|
||||
$_filename = $filename;
|
||||
$filename = $this->validateFilename($filename);
|
||||
if($this->lowercase) $filename = strtolower($filename);
|
||||
|
||||
if(!$filename && $this->name) {
|
||||
// if filename doesn't validate, generate filename based on field name
|
||||
$ext = pathinfo($_filename, PATHINFO_EXTENSION);
|
||||
$filename = $this->name . ".$ext";
|
||||
$filename = $this->validateFilename($filename);
|
||||
$this->overwrite = false;
|
||||
}
|
||||
|
||||
$destination = $this->destinationPath . $filename;
|
||||
$p = pathinfo($destination);
|
||||
|
||||
if($filename) {
|
||||
|
||||
if($this->lowercase) {
|
||||
$filename = function_exists('mb_strtolower') ? mb_strtolower($filename) : strtolower($filename);
|
||||
}
|
||||
|
||||
$exists = file_exists($destination);
|
||||
|
||||
if(!$this->overwrite && $filename != $this->overwriteFilename) {
|
||||
@@ -458,11 +478,19 @@ class WireUpload extends Wire {
|
||||
$this->overwrittenFiles[$bakDestination] = $destination;
|
||||
}
|
||||
|
||||
if($ajax) $success = @rename($tmp_name, $destination);
|
||||
else $success = move_uploaded_file($tmp_name, $destination);
|
||||
if($ajax) {
|
||||
$success = @rename($tmp_name, $destination);
|
||||
} else {
|
||||
$success = move_uploaded_file($tmp_name, $destination);
|
||||
}
|
||||
} else {
|
||||
$error = "Filename does not validate";
|
||||
}
|
||||
|
||||
if(!$success) {
|
||||
$this->error("Unable to move uploaded file to: $destination");
|
||||
if(!$destination || !$filename) $destination = $this->destinationPath . 'invalid-filename';
|
||||
if(!$error) $error = "Unable to move uploaded file to: $destination";
|
||||
$this->error($error);
|
||||
if(is_file($tmp_name)) @unlink($tmp_name);
|
||||
return false;
|
||||
}
|
||||
@@ -722,7 +750,7 @@ class WireUpload extends Wire {
|
||||
*
|
||||
* @param array|Wire|string $text
|
||||
* @param int $flags
|
||||
* @return $this
|
||||
* @return Wire|WireUpload
|
||||
*
|
||||
*/
|
||||
public function error($text, $flags = 0) {
|
||||
|
Reference in New Issue
Block a user