Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: is_file() i file_exists() zwracają zawsze FALSE pomimo tego, że plik istnieje
Forum PHP.pl > Forum > PHP
Raven1122
Witam,

mam problem z tym, że is_file jak i file_exists zwracają zawsze FALSE.

Już przedstawiam problem w kodzie:


  1. if(file_exists('/'.$this->modelpath)){
  2. if($id == null){
  3. include $this->modelpath;
  4. }
  5. else{
  6. include $this->modelpath.'?nid=' . $id;
  7. }
  8. }
  9. else{
  10. echo("false");
  11. }


$this->modelpath wypluwa: /inc/models/onas.php

Ten plik istnieje. Link wygląda następująco http://127.0.0.1/onas

Pomyślałem więc, że przeszkadza tutaj "onas", więc dodałem przed modelpath "/", tak aby sprawdzał od samego roota, jednak to także nie pomogło.

Nie mam już sił do tego, proszę o pomoc sad.gif

Z góry dziękuje.


@EDIT

Dodam jeszcze plik .htaccess
  1. RewriteEngine On
  2. RewriteCond %{REQUEST_FILENAME} !-f
  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php



mar1aczi
Ścieżki do plików w funkcji musisz podać względem miejsca gdzie znajduje się wykonywany skrypt.
Raven1122
probowalem takze ../ lecz nie pomoglo, jak pominac czlon onas ?
aras785
Zapodaj tutaj strukture i wszystko co masz to pomożemy wink.gif
Raven1122
Cala klasa Router:
  1. <?php
  2.  
  3. class Router{
  4.  
  5. protected $baseURL;
  6. protected $parsedURL;
  7. protected $modelpath;
  8. protected $id;
  9. public $model;
  10.  
  11. public function __construct(){
  12. //Ustawienie ścieżki do modeli
  13. $this->baseURL = "/inc/models/";
  14. return $this->baseURL;
  15. }
  16.  
  17.  
  18. public function _parseURL($model){
  19. //Zapisanie tablicy z podzielonym adresem URL
  20. $this->parsedURL = explode('/', $model);
  21. if(ctype_alpha($this->parsedURL[1])){
  22. $this->modelpath = $this->baseURL . $this->parsedURL[1] . '.php';
  23.  
  24. if(array_key_exists(2, $this->parsedURL) && $this->parsedURL[2] != ''){
  25. $this->id = $this->parsedURL[2];
  26. $this->model = $this->parsedURL[1];
  27. return array(
  28. 'id' => $this->id,
  29. 'modelpath' => $this->modelpath,
  30. 'model' => $this->model
  31. );
  32.  
  33.  
  34. }
  35. else{
  36. $this->id = null;
  37. $this->model = $this->parsedURL[1];
  38. return array(
  39. 'id' => $this->id,
  40. 'modelpath' => $this->modelpath,
  41. 'model' => $this->model
  42. );
  43.  
  44. }
  45. }
  46. else{
  47. //header("Location:index.php");
  48. }
  49. }
  50.  
  51.  
  52. public function _setRoute($model, $id, $modelpath){
  53. if(file_exists('/'.$this->modelpath)){
  54. if($id == null){
  55. include $this->modelpath;
  56. }
  57. else{
  58. include $this->modelpath.'?nid=' . $id;
  59. }
  60. }
  61. else{
  62. echo("NIE MA!");
  63. }
  64.  
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. }
  73.  
  74. ?>


index.php
  1. <?php
  2. function __autoload($classname){
  3. include strtolower($classname) . '.php';
  4. }
  5. $router = new Router();
  6. $info = $router->_parseURL($_SERVER["REQUEST_URI"]);
  7. $router->_setRoute($info['model'], $info['id'], $info['modelpath']);
  8. echo $info['id'];
  9. ?>


folder inc/models odrazu kolo index.php

.htaccess:
  1. RewriteEngine On
  2. RewriteCond %{REQUEST_FILENAME} !-f
  3. RewriteCond %{REQUEST_FILENAME} !-d
  4. RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php
aras785
router.php

  1. <?php
  2.  
  3. class Router{
  4.  
  5. protected $baseURL;
  6. protected $parsedURL;
  7. protected $modelpath;
  8. protected $id;
  9. public $model;
  10.  
  11. public function __construct(){
  12. //Ustawienie ścieżki do modeli
  13. $this->baseURL = "inc/models/";
  14. return $this->baseURL;
  15. }
  16.  
  17.  
  18. public function _parseURL($model){
  19. //Zapisanie tablicy z podzielonym adresem URL
  20. $this->parsedURL = explode('/', $model);
  21. if(ctype_alpha($this->parsedURL[1])){
  22. $this->modelpath = $this->baseURL . $this->parsedURL[1] . '.php';
  23.  
  24. if(array_key_exists(2, $this->parsedURL) && $this->parsedURL[2] != ''){
  25. $this->id = $this->parsedURL[2];
  26. $this->model = $this->parsedURL[1];
  27. return array(
  28. 'id' => $this->id,
  29. 'modelpath' => $this->modelpath,
  30. 'model' => $this->model
  31. );
  32.  
  33.  
  34. }
  35. else{
  36. $this->id = null;
  37. $this->model = $this->parsedURL[1];
  38. return array(
  39. 'id' => $this->id,
  40. 'modelpath' => $this->modelpath,
  41. 'model' => $this->model
  42. );
  43.  
  44. }
  45. }
  46. else{
  47. //header("Location:index.php");
  48. }
  49. }
  50.  
  51.  
  52. public function _setRoute($model, $id, $modelpath){
  53. if(file_exists($this->modelpath)){
  54. if($id == null){
  55. include $this->modelpath;
  56. }
  57. else{
  58. include $this->modelpath.'?nid=' . $id;
  59. }
  60. }
  61. else{
  62. echo("NIE MA!");
  63. }
  64.  
  65.  
  66.  
  67. }
  68.  
  69.  
  70.  
  71.  
  72. }
  73.  
  74. ?>
u mnie teraz działa wink.gif

sprawdzałem na: dom.localhost.pl/onas struktura katalogu dla tej domenki:
./index.php
./router.php
/inc/models/onas.php

onas.php
  1. Strona o nas :)


+ Wysypuję się gdy nie masz skryptu pod główną domeną ale to sobie sam sprawdzisz i poprawisz wink.gif Pozdrawiam
Raven1122
Dziala, dziekuje smile.gif Oczywiscie daje pomógł
aras785
router.php
  1. <?php
  2.  
  3. class Router{
  4.  
  5. protected $baseURL;
  6. protected $parsedURL;
  7. protected $modelpath;
  8. protected $id;
  9. public $model;
  10. public $path_dir;
  11.  
  12. public function __construct(){
  13. //Ustawienie ścieżki do modeli
  14. $this->baseURL = "inc/models/";
  15. return $this->baseURL;
  16. }
  17.  
  18.  
  19. public function _parseURL($model){
  20. //jesli skrypt nie znajduje się w głównej domenie
  21. if(!empty($this->path_dir)) $model = str_replace($this->path_dir,'',$model);
  22. //Zapisanie tablicy z podzielonym adresem URL
  23. $this->parsedURL = explode('/', $model);
  24. if(ctype_alpha($this->parsedURL[1])){
  25. $this->modelpath = $this->baseURL . $this->parsedURL[1] . '.php';
  26.  
  27. if(array_key_exists(2, $this->parsedURL) && $this->parsedURL[2] != ''){
  28. $this->id = $this->parsedURL[2];
  29. $this->model = $this->parsedURL[1];
  30. return array(
  31. 'id' => $this->id,
  32. 'modelpath' => $this->modelpath,
  33. 'model' => $this->model
  34. );
  35.  
  36.  
  37. }
  38. else{
  39. $this->id = null;
  40. $this->model = $this->parsedURL[1];
  41. return array(
  42. 'id' => $this->id,
  43. 'modelpath' => $this->modelpath,
  44. 'model' => $this->model
  45. );
  46.  
  47. }
  48. }
  49. else{
  50. //header("Location:index.php");
  51. }
  52. }
  53.  
  54.  
  55. public function _setRoute($model, $id, $modelpath){
  56. if(file_exists($this->modelpath)){
  57. if($id == null){
  58. include $this->modelpath;
  59. }
  60. else{
  61. include $this->modelpath.'?nid=' . $id;
  62. }
  63. }
  64. else{
  65. echo("NIE MA!");
  66. }
  67.  
  68.  
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75. }
  76.  
  77. ?>

index.php
  1. <?php
  2. function __autoload($classname){
  3. include strtolower($classname) . '.php';
  4. }
  5. $router = new Router();
  6. $router->path_dir = '/strona'; //localhost.pl/strona
  7. $info = $router->_parseURL($_SERVER["REQUEST_URI"]);
  8. $router->_setRoute($info['model'], $info['id'], $info['modelpath']);
  9. echo $info['id'];
  10. ?>


Teraz możesz wgrywać skrypt do katalogów np. localhost.pl/strona/onas smile.gif
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.