将文件上传到服务器的完整路径

I'm getting error while uploading files

I created function that uploads files. the problem is that I'm calling it from different file and different folders, which means that my path to the image folder's is changing. because of that i'm using the full path.

(I do have folder named - "images/usersFiles")

Warning: move_uploaded_file(http://localhost/dogger/images/usersFiles/13981072220-1.jpg) [function.move-uploaded-file]: failed to open stream: HTTP wrapper does not support writeable connections in C:\Program Files (x86)\wamp\www\dogger\func\func.global.php on line 127

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Program Files (x86)\wamp\tmp\php9D89.tmp' to 'http://localhost/dogger/images/usersFiles/13981072220-1.jpg' in C:\Program Files (x86)\wamp\www\dogger\func\func.global.php on line 127

I'm running the code from my local computer:

if ($_SERVER['REMOTE_ADDR'] == "127.0.0.1")
    $usersFiles = 'http://localhost/dogger/images/usersFiles/';  
else
    $usersFiles = '/home/israelig/public_html/sites/dogger/images/usersFiles/';  


if (move_uploaded_file($files['file']['tmp_name'][$i], $usersFiles.$files['file']['name'][$i]))

As the error message says, move_uploaded_file doesn't support writing to HTTP. You have to use a local file path, not a URL.

Use absolute path without http, like this (I dont use windows and can mistake):

C:\Program Files (x86)\wamp\www\dogger\userFiles

You can generate this path with:

realpath(dir(__FILE__) . '/../userFiles')

where FILE contains path of current script

Try this way,

if (move_uploaded_file($files['file']['tmp_name'], '/path/to/userFiles/'.$files['file']['name']))
{
    echo "File uploaded.";
    echo "<img src='/path/to/userFiles/{$files['file']['name']}' />";
}

EDIT:

Your directory structure:

C:\Program Files (x86)\
|-----------------------wamp\
                           |--www\
                                |---dogger\   <-- Assuming here is your upload.php which will be uploading image.
                                      |-----images\
                                               |-----usersFiles\    <-- Image will be uploaded here.

wamp\www\dogger\upload.php

<?php
    if (move_uploaded_file($files['file']['tmp_name'], './images/usersFiles/'.$files['file']['name']))
    {
        echo "File uploaded.<br/>";
        echo "<img src='./images/usersFiles/{$files['file']['name']}' />"; //displaying image using relative path.
        //OR
        echo "<img src='http://localhost/dogger/images/usersFiles/{$files['file']['name']}' />"; //displaying image using absolute path
    }

?>