Hello, in PHP only 3 days, I am writing a base for an iOS device, I only know Objective-C, so please do not criticize me in the noobies.

And so, the question for connoisseurs:

You need php code that will look at the "users /" folder (in which the files are: 1.php, 2.php, 3.php, etc.), and track the final file, in this case 3.php, and create - 4.php via fopen.

Can you please code, or an explanation of how to write this ..

    1 answer 1

    You obviously need a database, but if you want this way, then

    $dir = 'users'; $files = scandir($dir); // ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ список всСх Ρ„Π°ΠΉΠ»ΠΎΠ² $maxId = 0; foreach ($files as $file) { $id = (int)$file; if ($id === 0) { // отсСиваСм Ρ‚Π΅ Ρ„Π°ΠΉΠ»Ρ‹, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ Π½Π΅ Π½Π°Ρ‡ΠΈΠ½Π°ΡŽΡ‚ΡΡ с числа (Π° это, ΠΊΠ°ΠΊ ΠΌΠΈΠ½ΠΈΠΌΡƒΠΌ, '..' ΠΈ '.' continue; } else if ($maxId < $id) { $maxId = $Id; // записываСм ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½Ρ‹ΠΉ айдишник } } $filename = $dir.DIRECTORY_SEPARATOR.($maxId + 1).'.php'; // Ρ„ΠΎΡ€ΠΌΠΈΡ€ΡƒΠ΅ΠΌ имя Ρ„Π°ΠΉΠ»Π°, прибавляя ΠΊ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½ΠΎΠΌΡƒ Π°ΠΉΠ΄ΠΈ 1 $fileHandle = fopen($filename, 'w'); 

    In general, there is a smarter approach, but now I have to run.

    • Thank you, well, in general, I would like to create through muscle, but what I'm doing is not worth it) Thank you very much) - SuperPonchik
    • $ maxId = 0 ;, does not want to record the maximum ID, therefore adds directly to zero, how to solve? - SuperPonchik
    • Id was instead of id, when recording the maximum ID, everything works fine. Thank you - SuperPonchik