# Loading modx 3 images

**URL:** <https://community.modx.com/t/loading-modx-3-images/7102>\
**Category:** Random\
**Created:** [October 2, 2023, 12:55pm UTC](https://community.modx.com/t/loading-modx-3-images/7102 "2023-10-02T12:55:01Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 12:55pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/1 "2023-10-02T12:55:01Z")

</div>

Hello. There was a problem with loading images. Appeared today. No changes have been made to the site. Checked in two browsers. The hosting provider checked their problem is not reproducible and the download is carried out. I don’t have. Such a window freezes.

 ![2023-10-02_175244](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/8/8bd6e0b5f9d1711e1d1e26cdeca1ba0854f9b425.png)

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [October 2, 2023, 1:23pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/2 "2023-10-02T13:23:41Z")

</div>

The output from the “Console” tab in the _browser developer tools_ (that is shown in your screenshot) is not very helpful.

Can you change to the “Network” tab and check what request exactly creates the problem? What is the response of this request?

---

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 1:37pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/3 "2023-10-02T13:37:34Z")

</div>

Uploading: 2023-10-02\_183605.png…

 ![2023-10-02_183605](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/c/c76d4f67da7710d0e419b2e699f6d3d6432cf8a3.png)

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [October 2, 2023, 1:57pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/4 "2023-10-02T13:57:11Z")

</div>

This screenshot doesn’t tell me much.  
There is a list of requests at the bottom of the screenshot. Search the one that returns HTML instead of JSON (and therefore causes the error).

What is the exact action you perform when the error appears? Are you trying to select an image for a template variable?

---

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 2:31pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/5 "2023-10-02T14:31:46Z")

</div>

these files are now gone

 ![2023-10-02_193027](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/b/bd3f9064b10e9c107fd4d5696a79ae8510539a2c.png)

I’m uploading an image

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [October 2, 2023, 2:40pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/6 "2023-10-02T14:40:35Z")

</div>

Open the developer tools first and go to the “Network” tab.  
Then try to upload the image.  
The generated requests should appear in the list (again).  
Select them (one by one) in the list and check the response. (The one that creates the problem probably has the “action” parameter = `Browser/File/Upload`).

---

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 2:48pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/7 "2023-10-02T14:48:14Z")

</div>

![2023-10-02_194654](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/c/c3bbf92b014d9f2983c0e0c36dedfc386bd98891.png)  
 ![2023-10-02_194642](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/e/e091a89941b8d914a0ac90a3662a90cca851a363.png)  
 ![2023-10-02_194621](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/b/b79489f0812046079d1eab024cc7755ee2038030.png)

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [October 2, 2023, 2:55pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/8 "2023-10-02T14:55:19Z")

</div>

So it’s probably the one with the Название = `index.php?fileapi1696...` (or maybe another one with `index.php`).

Click on the request and look at the **response**.

 ![network_tab](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/c/c2151f6c0f0e16a5eb3dfb1af8182e9b0d72f521.png)

What’s in the response? Is it HTML instead of JSON?

---

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 2:58pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/9 "2023-10-02T14:58:35Z")

</div>

![1](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/e/ea1ebd8be9a22785afe7a19cbf4a468cb28e1abd.png)  
 ![2](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/2/2ea85dc4558196201bd4c51a45dc08b211aec32b.png)  
 ![3](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/f/f41781f4e5517adc527a0e94f9e7a5c9262784f7.png)

---

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 3:00pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/10 "2023-10-02T15:00:12Z")

</div>

> [@halftrainedharry](#):
>
> index.php

other JSON index.php

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [October 2, 2023, 3:03pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/11 "2023-10-02T15:03:19Z")

</div>

In the screenshot you posted above, you are on the tab “Заголовки”. Can you go to “Ответ” instead!

---

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 3:06pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/12 "2023-10-02T15:06:39Z")

</div>

Ответ

```auto
<br/>
<b>Fatal error</b>
: require_once() [<a href='0function.require0'>function.require0</a>
]: Failed opening required '/home/n/noreplzh/noreplzh.beget.tech/public_html/core/model/phpthumb/phpthumb.class.php' (include_path='.:/usr/share/php') in <b>/home/n/noreplzh/noreplzh.beget.tech/public_html/core/cache/includes/elements/modx/revolution/modplugin/34.include.cache.php</b>
on line <b>5</b>
<br/>

```

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [October 2, 2023, 3:14pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/13 "2023-10-02T15:14:21Z")

</div>

> [@mcv11111](#):
>
> `modplugin/34.include.cache.php`

So the Plugin with the ID = 34 generates a fatal error?

In the manager → tab “Elements” (“Элементы”), scroll down to the “Plugins” (“Плагины”) section and check what plugin has the ID = 34. (You may have to open the folders to see the ID that is in round brackets after the plugin name). From what _extra_ is this plugin?

---

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 3:18pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/14 "2023-10-02T15:18:33Z")

</div>

![2023-10-02_201643](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/2X/7/72c6d05a4e8269c1f4e995732756f30fbaa7bbc7.png)

```auto
<?php
// проверяем нужное событие
if ($modx->event->name != 'OnFileManagerUpload') {return;}
// подключаем phpthumb
require_once MODX_CORE_PATH.'model/phpthumb/phpthumb.class.php';
// настройки плагина
$config = array(
 'assets/upload/folder1/' => array(
   'src' => array('w' => 800,'h' => 600,'zc' => 1,'bg' => '#fff','q' => 90),
 ),
 'assets/upload/folder2/' => array(
   'src' => array('w' => 400,'h' => 300,'zc' => 1,'bg' => '#fff','q' => 90),
   'thumb' =>array('w' => 200,'h' => 150,'zc' => 1,'bg' => '#fff','q' => 70),
 ),
);
// параметры загружаемого файла
$file = $modx->event->params['files']['file'];
$directory = $modx->event->params['directory'];
// получаем media source
$ms = $modx->event->params['source'];
if($ms == null){
 return;
}
// настройки media source
$msProperties = $ms->get('properties');
$directory = $msProperties['basePath']['value'].$directory;
// на всякий случай проверяем наличие // и заменяем на /
$directory = str_replace('//', '/', $directory);
// смотрим, что при загрузке не возникло ошибок
if ($file['error'] != 0) {
 return;
}
$name = $file['name'];
$extensions = explode(',', $modx->getOption('upload_images'));
// проверям, что наша категория задана в настройках плагина
if (array_key_exists($directory, $config)) {
 $config = $config[$directory];
}
else {
 return;
}
// путь к файлу, имя файла, расширение
$filename = MODX_BASE_PATH.$directory.$name;
$def_fn = pathinfo($name, PATHINFO_FILENAME);
$ext = pathinfo($name, PATHINFO_EXTENSION);
// проверяем, что расширение файла задано в настройках MODX, как изображение
if (in_array($ext, $extensions)) {
 $sizes = getimagesize($filename);
 $format = substr($sizes['mime'],6);
 // бежим по всем полям массива с конфигом
 foreach($config as $imgKey =>$imgConfig){
   $options = '';
   if($imgKey == 'src'){
     // для ключа src имя файла совпадает с исходным
     $imgName = $filename;
   }
   else{
     // формируем имя файла
     //$imgName = MODX_BASE_PATH.$directory.$def_fn.'.'.$ext.'.'.$imgKey.'.'.$ext;
     $imgName = MODX_BASE_PATH.$directory.$def_fn.'_'.$imgKey.'.'.$ext;
   }
   // создаем объект phpThumb..
   $phpThumb = new phpThumb();
   // ..и задаем параметры
   $phpThumb->setSourceFilename($filename);
   foreach ($imgConfig as $k => $v) {
     $phpThumb->setParameter($k, $v);
   }
   // генерируем файл
   if ($phpThumb->GenerateThumbnail()) {
     if ($phpThumb->RenderToFile($imgName)) {
     // устанавливаем права на файл, это опционально, зависит от сервера
     chmod($imgName, 0666);
     }
   }
 }
}

```

---

<div class="post-metadata">

**Author:** ![halftrainedharry](https://community.modx.com/user_avatar/community.modx.com/halftrainedharry/32/1063_2.png) [@halftrainedharry](https://community.modx.com/u/halftrainedharry)\
**Post date:** [October 2, 2023, 3:24pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/15 "2023-10-02T15:24:29Z")

</div>

> [@mcv11111](#):
>
> `require_once MODX_CORE_PATH.'model/phpthumb/phpthumb.class.php';`

The extra _ResizeImageOnUpload_ is very old and this path only works on MODX 2.x.  
If you really need to use this extra with MODX 3, then take a look at this thread:

> [@ResizeImageOnUpload plugin and MODX3](https://community.modx.com/t/resizeimageonupload-plugin-and-modx3/6703):
>
> Hello everyone, Has anyone of you got the plugin “Resize Image On Upload” to work under Modx 3? I changed the “require\_once” path from “/core/model/phpthumb/phpthumb.class.php” to “/core/vendor/james-heinrich/phpthumb/phpthumb.class.php”. This was displayed as an error in the error log. But after the change I have no more errors in the logs but it still doesn’t work properly. Has anyone had any experience with this? Alternative question: How do you do that for your customers/authors who are …

---

<div class="post-metadata">

**Author:** ![mcv11111](https://community.modx.com/letter_avatar_proxy/v4/letter/m/6de8d8/32.png) [@mcv11111](https://community.modx.com/u/mcv11111)\
**Post date:** [October 2, 2023, 3:28pm UTC](https://community.modx.com/t/loading-modx-3-images/7102/16 "2023-10-02T15:28:19Z")

</div>

thank you.disabled it. I do not know what it is installed for
