0

I want to get the full path of image in PHP. I used <input> tag for image uploading. I'm unable to get the full path. when I alert the value of <input type="file">, I'm getting

c:/fake-path/image.jpg

Here is my code:

<input type="file" name="upload_captcha_background" id="upload_captcha_background" />
var file_path= jQuery("#upload_captcha_background").val();
alert(file_path);

and in PHP I'm fetching the value like:

$ux_image_path  =$_FILES['upload_captcha_background'];
Jerry
  • 70,495
  • 13
  • 100
  • 144
user2746093
  • 33
  • 3
  • 4
  • 10
  • 1
    Did you read here? There's an example on uploading files http://php.net/manual/en/function.move-uploaded-file.php. You can't read the full path with JavaScript, it's a security measure. – elclanrs Sep 24 '13 at 05:40
  • @elclanrs is correct, you cannot see the path of the file the computer the person is uploading it from. – alexg Sep 24 '13 at 05:45
  • i 9 but i canot use this move_uploaded_file. is there any other way of getting full path of image? – user2746093 Sep 24 '13 at 05:59

3 Answers3

0

If you mean the path where the image was located on the user computer before he/she uploaded it to your form - you can never know it in php or javascript or anywhere else.

In PHP you can see the path on SERVER (usually in the temporary folder) where the file was stored so you can read or copy it. If may just happen that the server is as well your user computer (i.e. you are testing the website on http :// localhost) but don't confuse those two things.

Marina
  • 491
  • 3
  • 9
0

the structure for

$_FILES[]

as follows /* Array ( [image] => Array ( [name] => Array ( [0] => 400.png ) [type] => Array ( [0] => image/png ) [tmp_name] => Array ( [0] => /tmp/php5Wx0aJ ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 15726 ) ) ) */

if you are trying to upload a file and copy it to a directory use the following code

$tmp_name = $_FILES['upload_captcha_background']["tmp_name"];
$name = $_FILES['upload_captcha_background']['name'];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
Beep.exe
  • 1,368
  • 12
  • 21
0

You can never be sure of getting a full filepath or even a reliable filename or content-type submitted in a file upload file.

you should never do so....and i think trying it in latest browsers is useless(from what i know) .. all latest browsers on the other hand , will not allow this.

Some related Stackoverflow questions:

Community
  • 1
  • 1
Moeed Farooqui
  • 3,604
  • 1
  • 18
  • 23