Php 上传图像时如何获取图像的完整路径

Php 上传图像时如何获取图像的完整路径,php,jquery,Php,Jquery,我试图上传图像,但它并没有采取图像的填充路径。它只接受扩展名为的文件名 <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script type="text/javascript"> $(

我试图上传图像,但它并没有采取图像的填充路径。它只接受扩展名为的文件名

<!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){

            $("#sok").on('click',function(e){
                //alert("Ok");
                e.preventDefault();
                var imf = $("#FoodieProfileImage").val();
                alert(imf);
                $.ajax({
                    url: 'Image.php',
                    type: 'POST',
                    data: imf,
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function () {
                      //alert(returndata);
                    //  $("#target").html(data);
                    },
                    error: function(){

                    }
                }); 

            });
        });
    </script>
    </head>
        <div class="modal-body">
        <form id="editUserForm" method="post" action="Image.php" enctype="multipart/form-data">
            <div class="form-group">
                <label>Profile Image</label>            
                <input type="file" accept="image/*" name="FoodieProfileImage" id="FoodieProfileImage"/>             

            </div>
        </form>
        <div id="target"></div>
        </div>
        <div class="modal-footer">
            <input type="button" id="sok" value="ok"/>
        </div>
    </html>

$(文档).ready(函数(){
$(“#sok”)。在('click',函数(e){
//警报(“正常”);
e、 预防默认值();
var imf=$(“#FoodieProfileImage”).val();
警报(货币基金组织);
$.ajax({
url:'Image.php',
键入:“POST”,
数据:国际货币基金组织,
async:false,
cache:false,
contentType:false,
processData:false,
成功:函数(){
//警报(返回数据);
//$(“#目标”).html(数据);
},
错误:函数(){
}
}); 
});
});
轮廓图像
php脚本如下所示:

<?php
if(!empty($_FILES["FoodieProfileImage"]["name"]) && $_FILES["FoodieProfileImage"]["size"] > 0) {

//Set upload path
$uploadPath =  "images/";
echo $uploadPath;//print_r();
exit();
//Check for is directoty exist ot not, if not then create new directoty
if (!is_dir($uploadPath)) {
    mkdir($uploadPath);
     chmod($uploadPath, 0755);
}
if(isset($_FILES["FoodieProfileImage"]['name'])) {
    $fileName = $_FILES["FoodieProfileImage"]["name"];
    //$fileName = realpath($fileName);
    //print_r(S_FILES);exit();
    //$newUserDetail['profileImage'] = $fileName;
    //pathinfo - Is a function that seperates file name, extension, basename

    $path_parts = pathinfo($fileName);

    $fileName = str_replace(" " , "_", strtolower($path_parts['filename'])); // Replaces all spaces with hyphens.
    $fileName = preg_replace('/[^A-Za-z0-9\-]/', '', $fileName); // Removes special chars.
    $fileName .= 'Foodie'.$userId ;

    //Create new file name
    move_uploaded_file($_FILES['FoodieProfileImage']["tmp_name"], $uploadPath . $fileName . '.' . $path_parts['extension']);

    //Get Path for Uploaded File
    $newUserDetail['profileImage'] = $uploadPath . $fileName. '.' . $path_parts['extension'];
    //print_r($newUserDetail['profileImage']);exit();
    //Get page image detail by page id
}

}
?>

服务器本身只能显示它所获得的数据,即使它知道文件路径,也无法访问它(因为您通过HTTP请求接收数据,而不是通过任何拉动方式)


可能可以解决您的任务的是通过JavaScript使用API,并实现一些逻辑,在上载图像的同时在客户端创建缩略图。

为什么任意Web服务器都应该知道客户端文件系统的详细信息?这对于完成任务不是必需的,因此客户端将只传输文件内容本身。确定。。我想在上传图像时显示图像预览,所以我选择图像的完整路径并尝试设置为#目标。