Destination path for move_uploaded_file in php

I need to know what to use for the destination path for the move function move_uploaded_file. (see http://php.net/manual/en/function.move-uploaded-file.php )

Now I have a code that works fine. My domain root directory contains the following elements (among others):
uploads <is the add-photo-submit.php folder <-this is a PHP file that uses move_uploaded_file

In add-photo-submit.php, I have the following line of code:

$target_path = "uploads/" . basename($_FILES['uploadedFile']['name']);

$ target_path is used as the destination parameter for the function. This works fine when I access the file through www.mydomain.com/add-photo-submit.php

However, I recently modified the .htaccess file to remove .php and add trailing slash. Now the PHP file is available at: www.mydomain.com/add-photo-submit/ I think the PHP file interprets the target path as "www.mydomain.com/add-photo-submit/uploads/filename.jpg"

I tried using the absolute path, but he said that I do not have permission ...

In the future, I would like to configure my root directory as follows: root
  -admin (folder)
    -add-photo-submit.php
  -uploads

Which link system has move_uploaded_file?

+5
source share
4 answers

You should use document_root to get the absolute path as follows:

$target_path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/" . basename($_FILES['uploadedFile']['name']);
+23

PHP , mod_rewrite URL-, . mod_rewrite example.com/index.php example.com/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/yz, PHP .

PHP script /home/sites/example.com/html/index.php, uploads/example.jpg , PHP /home/sites/example.com/html/uploads/example.jpg, , URL.

+1

$target_path = "../uploads/" . basename($fileUpload['name']);
0

dirname(__FILE__)   root (index.php)

$_SESSION["uploads_base_url"]=dirname(__FILE__); 

and now you can use it in any files where downloading is required.

echo $uploads_base_url=$_SESSION["uploads_base_url"];
0
source

All Articles