Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem z mkdir() proszę o pomoc :)
Forum PHP.pl > Forum > Przedszkole
lopez86
Witam, znalazłem skrypt który ma stworzyć folder oraz przekopiować z wybranej lokalizacji pliki do nowoutworzonego folderu. Skrypt tworzy nowy folder i kopiuje pliki ale nie do nowoutworzonego foldeu lecz do katalogu w którym nowy folder został utworzony - najprawdopodobniej jakiś błąd - próbowałem na sto sposobów i nic. Jeśli ktoś wie co zmienić i jak to proszę o pomoc:
Kod wygląda tak:





  1. <? echo $_GET['username']?> has been succesfully created <p>go to step 2
  2.  
  3. <?
  4. //Start Config
  5.  
  6. $homepath = "/home2/lopez86100/domains/mojadomena.com/public_html/article/"; 
  7. $filesdir = "/home2/lopez86100/domains/mojadomena.com/public_html/html/";
  8.  
  9. /* Add the files in which you want to copy from the old to the new directory. Use
     the same format as below! */
  10.  
  11. $cpFiles = array("add.gif","addovr.gif");
  12.  
  13. // End config
  14. reset($cpFiles);
  15.  
  16.  
  17. $userDir = $homepath.$username;
  18.  
  19. //create the new directory
  20. $newDir = mkdir($userDir, 0777);
  21.  
  22.  
  23. if (!$newDir) {
  24.  
  25. //If directory not created, end script and display error message
  26.  
  27. exit("The user directry was not created. Please try again or contact an Administr
    ator."
    );
  28.  
  29. }
  30.  
  31. ?>
  32. <? echo $_GET['username']?>
  33.  
  34. <?
  35.  
  36. //Begin copying files listed in the cpFiles array to the new directory.
  37.  
  38. foreach($cpFiles as $theFile) {
  39.  
  40. copy($filesdir.$theFile,$userDir.$theFile);
  41.  
  42. } //end foreach
  43.  
  44.  
  45.  //end else
  46.  
  47. ?>
Cysiaczek
  1. <?php
  2. $userDir = $homepath.$username;
  3. ?>

$username nie istnieje, a zatem ścieżka będzie zawierała jedynie ścieżkę do katalogu /articles

Daj na początku i powinno utworzyć.
  1. <?php
  2. $username='moj_katalog';
  3. ?>


Pozdrawiam i wesołych : )
juzwa
zwyczajnie zmienna $username musi byc pusta - i dlatego

gdybysw cześniej zrobił
1 - $username=$_GET['username'];
lub
2 - $userDir = $homepath.$_GET['username'];


to pewnie by zagadało
lopez86
Zrobiłem teraz działa ale błąd był gdzie indziej . Teraz kod wygląda tak - gdyby ktoś potrzebował. Wystarczy podpiąć formularz GET z html'a i wszystko gotowe biggrin.gif
  1. <?
  2. //Start Config
  3.  
  4. $homepath = "/home2/lopez86100/domains/easywebcity.com/public_html/article/"; 
  5. $filesdir = "/home2/lopez86100/domains/easywebcity.com/public_html/add/";
  6.  
  7. /* Add the files in which you want to copy from the old to the new directory. Use
     the same format as below! */
  8.  
  9. $cpFiles = array("add.gif","addovr.gif");
  10.  
  11. // End config
  12.  
  13. reset($cpFiles);
  14.  
  15. $username=$_GET['username'];
  16. $userDir = $homepath.$username;
  17.  
  18. //create the new directory
  19. $newDir = mkdir($userDir, 0777);
  20.  
  21.  
  22. if (!$newDir) {
  23.  
  24. //If directory not created, end script and display error message
  25.  
  26. exit("The user directry was not created. Please try again or contact an Administr
    ator."
    );
  27.  
  28. }
  29.  
  30. ?>
  31. <?
  32. $userDir = $homepath.$_GET['username'];
  33. chmod($userDir, 0777);
  34.  
  35. foreach($cpFiles as $theFile) {
  36.  
  37. $cpFiles = $cpFiless;
  38. copy($filesdir.$theFile,$userDir."/".$theFile);
  39.  
  40. } //end foreach
  41.  
  42.  //end else
  43.  
  44. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.