How to make, that did not show an error?

try { if(!$userPath = mkdir('./userFile/'.$_SESSION['user'].'/question/' . $date . '/' , 0700, true)) { throw new Exception('Ошибка.'); die(); } } catch (Exception $e) { echo '<p>ΠŸΡ€ΠΎΠΈΠ·ΠΎΡˆΠ»Π° ошибка.</p>' . $e->getMessage(); die(); } 

Shows Warning: mkdir(): Not a directory

  • Remove. $ e-> getMessage () - Vlad Vetrov
  • It does not work, it still shows Warning: mkdir (): Not a directory - DivMan

3 answers 3

 try { if(!$userPath = mkdir('./userFile/'.$_SESSION['user'].'/question/' . $date . '/' , 0700, true)) { throw new Exception('Ошибка.'); exit; } } catch (Exception $e) {} 
  • not working, shows Warning: mkdir (): Not a directory - DivMan
  • so this is not a mistake, but a warning, although in any case it works for me. if this hosting service may not have rights to create files or something else like that ... - Enforcer

If you want to remove the warning, it is enough to turn off warning output on the page or in the php.ini config file, for example, this code will not issue a warning:

 <?php error_reporting(E_ALL ^ E_WARNING); //ΠΎΡ‚ΠΊΠ»ΡŽΡ‡Π°Π΅ΠΌ прСдупрСТдСния Π½Π° этой страницС //Π”Π°Π»ΡŒΡˆΠ΅ ваш ΠΊΠΎΠ΄ try { if(!$userPath = mkdir('./userFile/'.$_SESSION['user'].'/question/' . $date . '/' , 0700, true)) { throw new Exception('Ошибка.'); } } catch (Exception $e) { echo '<p>ΠŸΡ€ΠΎΠΈΠ·ΠΎΡˆΠ»Π° ошибка.</p>' . $e->getMessage(); die(); } 

PS Only if all the code is really, I don’t understand why you use try-catch here.

    Suppress warnings for some function by adding a "dog" before calling it:

     if(!$userPath = @mkdir('./userFile/'.$_SESSION['user'].'/') { // ... 

    It is worth doing only if you yourself are handling the error. It will be good to check that the directory is there, without causing its creation unnecessarily.

    Disabling warnings for the entire code for the sake of one case is not the best idea.

     // Π½Π΅ Π΄Π΅Π»Π°ΠΉΡ‚Π΅ Ρ‚Π°ΠΊ // error_reporting(E_ALL ^ E_WARNING);