destination path for move_uploaded_file in php

You should use document_root to get absolute path like this:

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

PHP's local filename operations have no idea what mod_rewrite did to your urls, and deal only with actual raw file system paths. You could have mod_rewrite turn your nice simple example.com/index.php into a hideous 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 and PHP would still be running in the same physical directory on the server.

If the PHP script lives at /home/sites/example.com/html/index.php, and you use uploads/example.jpg as your move path, then PHP will attempt to put that image into /home/sites/example.com/html/uploads/example.jpg, regardless of what the requested URL was.


We can use dirname(__FILE__) instead of server root declare below line in any of root file(index.php)

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

and you can now use this in any files where upload is needed.

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