Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> tworzenie katalogu, poprawnie?
awariat
post
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 21.06.2008

Ostrzeżenie: (0%)
-----


czy ten kod jest poprawnie napisany?

CODE
$katalog = $_POST['katalog'];
$oldumask = umask(0);


if (file_exists($katalog)) {
echo "error=file $katalog exists&end=0";
} else {
if (!mkdir($katalog, 0777, true)) {
echo "error=Couldn't create directory $katalog&end=0";
} else {

echo "error=utworzono $katalog&end=0";
}
}
umask($oldumask);
?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
webmaniak
post
Post #2





Grupa: Zarejestrowani
Postów: 371
Pomógł: 30
Dołączył: 14.04.2010

Ostrzeżenie: (0%)
-----


Witam!
Chce stworzyć sobie funkcje która będzie odpowiedzialna za tworzenie katalogu. Mam taki skrypt:
  1. $old = umask(0);
  2. $rs=mkdir('folder',0777);
  3. umask($old);
  4. if( $rs )
  5. {
  6.  
  7. // print success information
  8. echo 'ok';
  9.  
  10. }else{
  11.  
  12. // print error information
  13. echo 'błąd';
  14.  
  15. }

i co ciekawe na windows działa, choć gdzieś wyczytałem że umask nie działa na windows, a na serwerze postawionym na fedora 11 nie działa. Mam do serwera pełny dostęp więc zmieniłem chmody na 777, by zobaczyć czy to dlatego. To komunikat błędu:
  1. Warning: mkdir() [function.mkdir]: Permission denied in [...]/funkcje_dokumentacja.php on line 342
  2. błąd

Co ciekawe kod wziąłem z manuala, przedstawia się on tak:
  1. function handleError() {
  2. trigger_error('MY ERROR');
  3.  
  4. /** usage sample
  5.   @handleError();
  6.   echo $php_errormsg;
  7.   */
  8. }
  9.  
  10. // detect slash/backslash nomenclature dirname
  11. $path = dirname( __FILE__ );
  12. $slash = '/';
  13.  
  14. (stristr( $path, $slash )) ? '' : $slash = '\\';
  15. define( 'BASE_DIR', $path . $slash );
  16.  
  17. $folder = time(); // folder name
  18. $dirPath = BASE_DIR . $folder; // folder path
  19.  
  20. // print results
  21. echo $slash;
  22. echo '<hr>';
  23.  
  24. $rs = @mkdir( $dirPath, 0777 );
  25. @handleError();
  26. if( $rs )
  27. {
  28.  
  29. // print success information
  30. echo 'was done!';
  31. echo '<br>folder: <a href="' . $folder . '">' . $folder . '</a>';
  32. echo '<br>dirPath: ' . $dirPath;
  33.  
  34. }else{
  35.  
  36. // print error information
  37. echo 'an error was occurred. Attempting create folder';
  38. echo '<br>dirPath: ' . $dirPath;
  39. echo '<br>php_errormsg: ' . $php_errormsg;
  40.  
  41. }

I działa zarówno na windows lokalnie jak i na serwerze. Co więc jest nie tak z tym pierwszym kodem??

Pomoże ktoś(IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 23:25