Всем доброго! У меня возникла проблема в получении имен файлов в создаваемом каталоге. Имеется код, он рабочий. В нем также закомментированные строки которые также работают и создают запись в файл. Суть в том ,что я не могу получить имена созданных файлов если использую закомментированный код. Второй файл, это что выводит в игру полученные имена из каталога. Кто то может знает в чем ошибка. PHP: <?php $email = isset($_POST['email']) ? htmlspecialchars($_POST['email']) : null; $title = isset($_POST['cartoontitle']) ? htmlspecialchars($_POST['cartoontitle']) : null; $object_id = isset($_POST['object_id']) ? htmlspecialchars($_POST['object_id']) : null; $start = isset($_POST['start_t']) ? htmlspecialchars($_POST['start_t']) : null; $layers = isset($_POST['layers']) ? htmlspecialchars($_POST['layers']) : null; $position_x = isset($_POST['position_x']) ? htmlspecialchars($_POST['position_x']) : null; $position_y = isset($_POST['position_y']) ? htmlspecialchars($_POST['position_y']) : null; $scale_x = isset($_POST['scale_x']) ? htmlspecialchars($_POST['scale_x']) : null; $scale_y = isset($_POST['scale_y']) ? htmlspecialchars($_POST['scale_y']) : null; $rotate = isset($_POST['rotate']) ? htmlspecialchars($_POST['rotate']) : null; $finish = isset($_POST['finish_t']) ? htmlspecialchars($_POST['finish_t']) : null; //$strone = "0|1|66,10|-7,90|3,00|3,00|0|0"; $str = "*" . $start . "|" . $layers . "|" . $position_x . "|" . $position_y . "|" . $scale_x . "|" . $scale_y . "|" . $rotate . "|" . $finish; $filetitle = $_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title . '/' . $object_id . '.txt'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($email && $title) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title)) { mkdir($_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title); $fh = fopen ($filetitle, 'c'); fseek($fh, 0, SEEK_END); $ret = fwrite($fh,$str); fclose($fh); if ($ret === false) die("Fwrite failed"); echo ("Success"); } } /* if ($email && $title) { if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title)) . '/' . $object_id . '.txt')) { $fh = fopen ($filetitle, 'c'); fseek($fh, 0, SEEK_END); $ret = fwrite($fh,$str); fclose($fh); if ($ret === false) die("Fwrite failed"); echo ("Success"); } else { mkdir($_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title); $fh = fopen ($filetitle, 'c'); fseek($fh, 0, SEEK_END); $ret = fwrite($fh,$strone); fclose($fh); if ($ret === false) die("Fwrite failed"); echo ("Success"); } } */ else httpNotFound(); } if ($_SERVER['REQUEST_METHOD'] === 'GET') { $request_uri = explode("/", $_SERVER['REQUEST_URI']); if (count($request_uri) == 4 && $request_uri[1] == 'cartoon/file') { $email = $request_uri[2]; $title = $request_uri[3]; $filetitle = $_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title; } } if (file_exists($filetitle)) echo file_get_contents($filetitle); else httpNotFound(); function httpNotFound() { http_response_code(404); header('Content-type: text/html'); echo <<<HTML <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>404 Not Found</title> </head><body> <h1>Not Found</h1> <p>The requested URL was not found on this server.</p> </body></html> HTML; exit; } PHP: <?php $email = isset($_POST['email']) ? htmlspecialchars($_POST['email']) : null; $title = isset($_POST['cartoontitle']) ? htmlspecialchars($_POST['cartoontitle']) : null; $filetitle = $_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($email && $title) { $arrFiles = array(); $objDir = dir($filetitle); while (false !== ($entry = $objDir->read())) { if ($entry != '.' && $entry != '..' ) { $arrFiles[] = $entry; } } foreach($arrFiles as $array_max) { $fileName= pathinfo($array_max, PATHINFO_FILENAME ); echo ("|" . $fileName); } $objDir->close(); } } ?>
Добрый день! Про то, что не закомментировано и как Вы утверждаете работает. PHP: if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title)) { mkdir($_SERVER['DOCUMENT_ROOT'] . '/cartoon/file/' . $email . '/' . $title); $fh = fopen ($filetitle, 'c'); fseek($fh, 0, SEEK_END); $ret = fwrite($fh,$str); fclose($fh); if ($ret === false) die("Fwrite failed"); echo ("Success"); } Здесь Вы создаёте директорию если она существует, в противном случае ничего не происходит. Если включён E_WARNING, то будет выдаваться предупреждение и mkdir вернёт false. Поробуйте переделать так: PHP: $dirName = $_SERVER['DOCUMENT_ROOT']."/cartoon/file/$email/$title"; $filetitle = "$dirName/$object_id.txt"; if(!file_exists($dirName)) mkdir($dirName); $fh = fopen ($filetitle, 'c'); fseek($fh, 0, SEEK_END); $ret = fwrite($fh, $str); fclose($fh); if ($ret === false) die("Fwrite failed"); else echo ("Success"); Удачи!