1

I'm trying to upload images to server, create a thumbnail from the uploaded image, and save the relative paths to mysql database . . . . The image path is

     /mysite/images/

from my site root (which is wamp/www/mysite/images in my local testing environment)

Now, I'm performing a directory check with

   if(!is_dir($path) && !is_writable($path)){
    throw new Exception ("$path is not valid .. ");
    }

where path is /mysite/images/ , thinking that initial '/' will denote the root.

But, the script was throwing an exception saying invalid path name, and my

     move_uploaded_file($tmp_name, $path.$filename)

too was not working.

PS: the path mysite/images/ also throws an error and the file is not moved

Now, I have worked around by appending document root manually to path name for both directory checks and move file , which is now looking like

      if(!is_dir($_SERVER['DOCUMENT_ROOT'].$path) && !is_writable($_SERVER['DOCUMENT_ROOT'].$path)){
    throw new Exception ("$path is not valid .. ");
    }

      move_uploaded_file($tmp_name, $_SERVER['DOCUMENT_ROOT'].$path.$filename)

I also changed the path to

    mysite/images/ 

removing the initial slash intended for site root. This is working perfectly.

But, I cannot understand why directory check and move uploaded file snippets are not taking site root relative links.

Any ideas is appreciated.

4

2 に答える 2

1

Your website path is not wamp/www/mysite/images.

You are using a web server, you cant access the drive like: c:/wamp ....

Once online, how will you access your files? Linux does not have c:/ ...

Your website path is: http://localhost/mysite/

Your image path is: http://localhost/mysite/images or ./images if your code is correctly written.

so, do this:

define('ROOT', $_SERVER['DOCUMENT_ROOT']);

include_once(ROOT."/mycfgfile.php");

or

include_once(ROOT."/includes/mycfgfile.php");
于 2012-10-22T07:35:29.523 に答える
1

The problem is with the path representation.

In linux /mysite will try to access the directory in the root level of file system. Windows this might not create an error. for is_file() kind of API's it should the absolute path and not relative ones.

于 2012-10-22T07:40:27.483 に答える