Chevereto 3.20+compatibility with Windows Server

preface

Recently, we are upgrading the system/environment for each server, and upgrading the programs of each site Chevereto I found a lot of problems. Of course, I have contacted the developer, but the reply is that it will not be particularly compatible with Windows. Please use Docker under Windows.
Although there are not many people running PHP on Windows, let alone Chevereto users, it is reasonable to exist. Go ahead without the official repair, and provide some ideas for you who happen to find this article. This article is based on: Chevereto 3.20.17&PHP 7.4.30; Chevereto 4.0.1 & PHP 8.1.11

Problems caused by different path separators

The path separator of Windows system is backslash (), while Linux system is forward slash (/). This result will appear when the PHP built-in function is used in the code to obtain the path, and then the path is spliced: D:\A\B/C/D.jpg There is nothing wrong with this. PHP can handle it normally. However, if you replace or compare this path string, you will have problems because D:\A\B/C/D.jpg and D:/A/B/C/D.jpg Not equal, but they point to the same file.

In Chevereto 3.20+, this problem will cause the user's avatar to be stuck after uploading, and in 4.0+, the website will not be able to load static resources normally. The repair is simple. Replace all backslashes () in the path string with forward slashes (/).

Chevereto 3.20. X Version: /app/lib/classes/class.localstorage.php:62
Chevereto 4.0. X Version: /app/src/Legacy/Classes/LocalStorage.php:63
take

 $target_filename = str_replace('/.\/', '/', $target_filename);

Change to

 $target_filename = str_replace('\\', '/', $target_filename);

You can solve the problem of jamming after uploading your avatar.

Used by developers /.\/ I don't understand what he wants to replace. If you understand, please leave a message. If you use \ As an escape, I want to /./ It is not allowed to replace it as irregular. It has been tested.

Chevereto 4.0. X Version: /app/src/Legacy/functions.php:926
take

 define('PATH_PUBLIC', dirname(__DIR__, 3) . '/');

Change to

 define('PATH_PUBLIC', str_replace('\\', '/', dirname(__DIR__, 3)) . '/');

The static resource loading problem can be solved.

Compatibility between Intervention Image and Windows

The save method of Intervention Image must use the image extension under Windows Chevereto is used throughout the image upload process tempnam() The. tmp file generated by the function will make an error when using the save method (this method is only used in jpg and bmp formats during uploading).

I used a simple method to fix this problem. When saving, add the original image extension, that is, save it as a. tmp.xxx file, and then rename the. tmp.xxx file back to the. tmp file. (Why not save it as a file with an image extension at the beginning? Because the. tmp file is generated first. If you want to change it this way, you need to change too many things, which may cause other problems.)

The following changes are for reference only. If you need to use them, please see the difference and make a backup. It is not advisable to use mindless Ctrl C V.
Chevereto 3.20. X Version: /app/lib/classes/class.upload.php:160
Chevereto 4.0. X Version: /app/src/Legacy/Classes/Upload.php:223
take

 if (array_key_exists('exif', $this->options)) { $this->source_image_exif = null; try { $this->source_image_exif = \exif_read_data($this->downstream); } catch (Throwable $e) { } if (isset($this->source_image_exif)) { $this->source_image_exif['FileName'] = $this->source_filename; if (isset($this->source_image_exif['Orientation'])) { ImageManagerStatic::make($this->downstream)->orientate()->save(); } } if (!$ this->options['exif']) { unset($this->source_image_exif); if (ImageManagerStatic::getManager()->config['driver'] === 'imagick') { $img = ImageManagerStatic::make($this->downstream); $img->getCore()->stripImage(); $img->save(); } else { $img = @imagecreatefromjpeg($this->downstream); if ($img) { imagejpeg($img, $this->downstream, 90); imagedestroy($img); } else { throw new UploadException("GD: Unable to create a new JPEG without Exif data", 444); } } } }

Change to

 if (array_key_exists('exif', $this->options)) { $this->source_image_exif = null; $tmp_name_img = $this->downstream . '.' . $ this->extension; try { $this->source_image_exif = \exif_read_data($this->downstream); } catch (Throwable $e) { } if (isset($this->source_image_exif)) { $this->source_image_exif['FileName'] = $this->source_filename; if (isset($this->source_image_exif['Orientation'])) { ImageManagerStatic::make($this->downstream)->orientate()->save($tmp_name_img); $renamed = rename($tmp_name_img, $this->downstream); } } if (!$ this->options['exif']) { unset($this->source_image_exif); if (ImageManagerStatic::getManager()->config['driver'] === 'imagick') { $img = ImageManagerStatic::make($this->downstream); $img->getCore()->stripImage(); $img->save($tmp_name_img); $renamed = rename($tmp_name_img, $this->downstream); } else { $img = @imagecreatefromjpeg($this->downstream); if ($img) { imagejpeg($img, $this->downstream, 90); imagedestroy($img); } else { throw new Exception("Unable to create a new JPEG without Exif data", 644); } } } }

OK.

Chevereto 3.20. X Version: /app/lib/classes/class.imageconvert.php:29
Chevereto 4.0. X Version: /app/src/Legacy/Classes/ImageConvert.php Rewrite the method, just look at it.
take

 public function __construct($source, $to, $destination, $quality=90) { if(! in_array($to, ['jpg', 'gif', 'png'])) { return $source; } $image = ImageManagerStatic::make($source); $image->encode($to, $quality)->save($destination); $this->out = $destination; }

Change to

 public function __construct($source, $to, $destination, $quality=90) { if(! in_array($to, ['jpg', 'gif', 'png'])) { return $source; } $source_img = $destination . '.' . $ to; $image = ImageManagerStatic::make($source); $image->encode($to, $quality)->save($source_img); $renamed = rename($source_img, $destination); $this->out = $destination; }

OK.

There are too many redirections of links containing Chinese after the "SEO optimization of image/album URL address" function is enabled

This problem only occurs to IIS users. It is caused by two factors. One is that IIS Rewrite uses GBK encoding in Chinese, and the other is that $_SERVER ['REQUEST_URI '] after IIS Rewrite gets the value after urldecode.

Chevereto 4.0. X Version: /app/src/Legacy/G/functions.php:1513
take

 $request_uri = server()['REQUEST_URI'] ?? '';

Change to

 $request_uri = mb_convert_encoding(server()['REQUEST_URI'], "utf-8", "gbk") ?? '';

Chevereto 4.0. X Version: app\legacy\routes\album.php:84
take

 if (! starts_with($album['url'], get_current_url())) {

Change to

 if (! starts_with(urldecode($album['url']), get_current_url())) {

Chevereto 4.0. X Version: app\legacy\routes\image.php:83
take

 if ($image['url_viewer'] !=  get_current_url(true, ['lang'])) {

Change to

 if (urldecode($image['url_viewer']) !=  get_current_url(true, ['lang'])) {

In fact, there is no radical cure, but it can be used.

Other issues

To be found. Welcome to leave a message to discuss.

give the thumbs-up
  1. Mr Kiss say:

    Dog, do you have a warranty on what you buy???? Very concerned

    1. It is written on the commodity map

  2. Mr Kiss say:

    The seller has misprinted

  3. It's a long night say:

    Xiaobaibai is still updating. She should have graduated. She really uses love to generate electricity :a:

    1. Now it's a jobless vagrant blog. It's more about mood. Anyway, it doesn't cost much

      1. Four Seasons Milk Green Whole Sugar with Ice say:

        The website is so beautiful. I can imitate a "Buhaha" (I found it when browsing the PHP theme

        1. It will soon become a Russian doll :huaji9:

          1. OwO say:

            Taowa

  4. slover say:

    Can the live2d2233 be configured for hexo?

  5. Thank you Lu say:

    I don't quite get it, but I think you are really terrific

  6. Find a bosom friend say:

    When I asked the author to publish the article, I uploaded the local video. After the article was published, I opened the article. The player window can't adapt to the application B station or the link of other platforms. I can ask how to use the local video as well as the platform link to adapt the player window. Ask the leader to teach me

  7. Li Si say:

    ha-ha

  8. Thank you very much for sharing this article. I learned a lot of new knowledge from it.

  9. This article is written in simple terms, which makes me understand it!

Post reply

E-mail addresses will not be made public. Required items are marked with *