#php #directory #fwrite
#php #каталог #fwrite
Вопрос:
Поэтому я создаю CMS, которая, когда пользователь загружает файл, создает новый каталог на основе имени пользователя (эта часть работает). Затем у меня есть код, создающий index.php и записывает в индекс php код, в основном похожий на шаблон. Все работает так, как я хочу, за исключением случаев, когда я пытаюсь заставить код считывать текущие файлы, перечисленные в новом каталоге, который мы только что создали. Может ли кто-нибудь помочь указать мне правильного директора для записи в новый индексный файл и указать каталог файлов для нового индексного файла.
if(move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $fixedPath. "/" . $name . "/" . $_FILES["fileToUpload"]["name"])) { //CreateIndex $createfile = fopen($fixedPath. "/" . $name . "/" .'index.php', 'x'); $fuck = $_FILES["fileToUpload"]["name"]; $myfile = fopen($fixedPath. "/" . $name . "/" .'index.php', "w") or die("Unable to open file!"); $txt = " lt;thgt;DEFENDANT FILESlt;/thgt; lt;/trgt; lt;/theadgt; lt;tbodygt;"; fwrite($myfile, $txt); $txt = "lt;?php include 'link.com/test/Directory.php';?gt; lt;/tbodygt; lt;/tablegt; lt;/divgt; lt;/divgt; lt;/bodygt;lt;/htmlgt;"; fwrite($myfile, $txt); fclose($myfile); echo "Stored in: " . $fixedPath. "/" . $name . "/" . $_FILES["fileToUpload"]["name"]; } else { echo "Error moving file"; } }
Код, который находится в Directory.php
lt;?php $dir = './'; // Check if the directory exists if (file_exists($dir) amp;amp; is_dir($dir) ) { // Get the files of the directory as an array $scan_arr = scandir($dir); $files_arr = array_diff($scan_arr, array('.','..') ); // Get each files of our directory with line break foreach ($files_arr as $file) { //Get the file path $file_path = "./".$file; // Get the file extension $file_ext = pathinfo($file_path, PATHINFO_EXTENSION); if ($file_ext=="jpg" || $file_ext=="png" || $file_ext=="JPG" || $file_ext=="PNG" || $file_ext=="php") { echo 'lt;trgt;lt;tdgt;lt;a href="', $file, '"gt;',$file,'lt;/agt;lt;/tdgt; lt;/trgt;'; } } } else { echo "Dorectory does not exists"; } ?gt;