Answers.Body: <p>Thanks to CiviHosting support, who pointed out that it was the display of the deprecated message that was making kcfinder misbehave.  The fix was to redirect all PHP errors and warnings to a file rather than to the display.  Adding this to php.ini did the trick:</p>
  <pre><code>error_reporting = E_ALL | E_STRICT
  log_errors = On
  display_errors = Off
  error_log = /[some dir]/php-errors.log
  </code></pre>
  <p>It was also suggested that I change to PHP handler to FPM (which makes sense for Drupal and WordPress installations).</p>
  <p>Both kcfinder and ckeditor4 are no longer supported, and are eventually going to break altogether with some future release of PHP.  I hope there are plans to replace them in CiviCRM.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-12-31T19:55:50.757Z
Answers.LastActivityDate: 2024-12-31T19:55:50.757Z
Answers.UserDisplayName: charlie
Body: <p>This problem arose after upgrading to CiviCRM 5.76.2 on Drupal 7.101 on a production Linux host running Apache and PHP 8.3.</p>
  <p>When adding an image to a mailing (CiviMail) by clicking on &quot;Browse Server&quot;, CKFinder cannot list the contents of the image upload folder.  The KCFinder window opens and shows &quot;Unknown error&quot; in both panels.  Others have had a similar problem, but none of the suggested solutions seem to work for me.</p>
  <p>The KCFinder window also shows the following message (which is odd considering that I have Drupal configured with error reporting off):</p>
  <blockquote>
  <p><strong>Deprecated</strong>: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/username/www/lists/sites/all/modules/civicrm/CRM/Utils/System/Drupal.php on line 284.</p>
  </blockquote>
  <p>Line 284 in Drupal.php is</p>
  <pre><code>    ```$base_url = str_replace('http://', 'https://', $base_url);```
  </code></pre>
  <p>which implies that $base_url is null.  That variable is set explicitly in settings.php.</p>
  <p>When I click instead on Upload, select a file, then click Upload to Server, I get a popup message &quot;Incorrect server response.&quot;  It turns out that the upload did succeed with the image put in the correct directory.  I can insert the image into the mailing if I enter the full image URL, but this is inconvenient.</p>
  <p>I had the same problem on a test installation on a macOS 14.6.1 system.  The Upload Directories and Resource URLs settings on both systems are identical (except for the host names).  The problem in this environment disappeared when I added a specific definition of [civicrm.files] to civicrm.settings.php.  Adding a similar definition to the production (Linux) system, however, did not do the trick.  I've tried adding specific definitions of [cms.root] and [civicrm.root] still to no effect.  This test server did not show any PHP warnings, even though it is configured to show all messages.</p>
  <p>There are no symbolic links in any of the relevant paths (I know this tickles a KCFinder anomaly).  There are no .htaccess files that would impede access to the upload folders.</p>
  <p>Any help in debugging this would be much appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-12-30T03:16:52.073Z
Comments.Text: More information: On a whim, I downgraded the installation from PHP 8.3 to 7.4. Now kcfinder works as it should. This is obviously not the best long term solution, nor does it explain why I have no problem on my test server with PHP 8.3. My production provider is CiviHosting.com
Comments.UserDisplayName: charlie
Tags: <kcfinder>
Title: KCFinder cannot show contents of image upload folder
ThreadText: # KCFinder cannot show contents of image upload folder
  
  (Asked by: username_0 on 2024-09-01)
  
  This problem arose after upgrading to CiviCRM 5.76.2 on Drupal 7.101 on a production Linux host running Apache and PHP 8.3.
  When adding an image to a mailing (CiviMail) by clicking on "Browse Server", CKFinder cannot list the contents of the image upload folder.  The KCFinder window opens and shows "Unknown error" in both panels.  Others have had a similar problem, but none of the suggested solutions seem to work for me.
  The KCFinder window also shows the following message (which is odd considering that I have Drupal configured with error reporting off):
  
  Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /home/username/www/lists/sites/all/modules/civicrm/CRM/Utils/System/Drupal.php on line 284.
  
  Line 284 in Drupal.php is
      ```$base_url = str_replace('http://', 'https://', $base_url);```
  
  which implies that $base_url is null.  That variable is set explicitly in settings.php.
  When I click instead on Upload, select a file, then click Upload to Server, I get a popup message "Incorrect server response."  It turns out that the upload did succeed with the image put in the correct directory.  I can insert the image into the mailing if I enter the full image URL, but this is inconvenient.
  I had the same problem on a test installation on a macOS 14.6.1 system.  The Upload Directories and Resource URLs settings on both systems are identical (except for the host names).  The problem in this environment disappeared when I added a specific definition of [civicrm.files] to civicrm.settings.php.  Adding a similar definition to the production (Linux) system, however, did not do the trick.  I've tried adding specific definitions of [cms.root] and [civicrm.root] still to no effect.  This test server did not show any PHP warnings, even though it is configured to show all messages.
  There are no symbolic links in any of the relevant paths (I know this tickles a KCFinder anomaly).  There are no .htaccess files that would impede access to the upload folders.
  Any help in debugging this would be much appreciated.
  
  **Tags:** kcfinder
  
  > **Comments:**
  > **username_0**: More information: On a whim, I downgraded the installation from PHP 8.3 to 7.4. Now kcfinder works as it should. This is obviously not the best long term solution, nor does it explain why I have no problem on my test server with PHP 8.3. My production provider is CiviHosting.com  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-12-31. Score: 1
  
  Thanks to CiviHosting support, who pointed out that it was the display of the deprecated message that was making kcfinder misbehave.  The fix was to redirect all PHP errors and warnings to a file rather than to the display.  Adding this to php.ini did the trick:
  error_reporting = E_ALL | E_STRICT
  log_errors = On
  display_errors = Off
  error_log = /[some dir]/php-errors.log
  
  It was also suggested that I change to PHP handler to FPM (which makes sense for Drupal and WordPress installations).
  Both kcfinder and ckeditor4 are no longer supported, and are eventually going to break altogether with some future release of PHP.  I hope there are plans to replace them in CiviCRM.
  
  
  ---
  
  