Craft\ImagerService::fixSlashes PHP Method

fixSlashes() static public method

Fixes slashes in path
static public fixSlashes ( $str, boolean | false $removeInitial = false, boolean | false $removeTrailing = false ) : mixed | string
$str
$removeInitial boolean | false
$removeTrailing boolean | false
return mixed | string
    static function fixSlashes($str, $removeInitial = false, $removeTrailing = false)
    {
        $r = str_replace('//', '/', $str);
        if (strlen($r) > 0) {
            if ($removeInitial && $r[0] == '/') {
                $r = substr($r, 1);
            }
            if ($removeTrailing && $r[strlen($r) - 1] == '/') {
                $r = substr($r, 0, strlen($r) - 1);
            }
        }
        return $r;
    }

Usage Example

 /**
  * ---- AWS -----------------------------------------------------------------------------------------------------------
  */
 public function uploadToAWS($filePath)
 {
     if (is_null($this->s3)) {
         $this->s3 = new \S3($this->getSetting('awsAccessKey'), $this->getSetting('awsSecretAccessKey'));
         $this->s3->setExceptions(true);
     }
     $file = $this->s3->inputFile($filePath);
     $headers = $this->getSetting('awsRequestHeaders');
     if (!isset($headers['Cache-Control'])) {
         $headers['Cache-Control'] = 'max-age=' . $this->getSetting('awsCacheDuration') . ', must-revalidate';
     }
     if (!$this->s3->putObject($file, $this->getSetting('awsBucket'), ImagerService::fixSlashes($this->getSetting('awsFolder') . '/' . str_replace($this->getSetting('imagerSystemPath'), '', $filePath), true, true), \S3::ACL_PUBLIC_READ, array(), $headers, $this->_getAWSStorageClass())) {
         ImagerPlugin::log("Upload to AWS failed for {$filePath} in ImagerService", LogLevel::Error);
     }
 }