获取完整的文件上传路径在PHP

时间:2018-07-09 11:31:27

标签: php file-upload

我对文件上传有疑问。我想打印用户PC上的原始文件路径(例如'C:\ Documents and settings \ guest \ documents \ test.txt') 我尝试了一些方法,但只获取文件名。.我需要打印完整路径

    <form action="" method="post" enctype="multipart/form-data">
        Select image to upload:
        <input type="file" name="fileToUpload" id="fileToUpload">
        <input type="submit" value="Upload Image" name="submit">
    </form>

    <?php
    $target_dir = "uploads/";
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
    $uploadOk = 1;


    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 5000000) {
        echo "Sorry, your file is too large.";
        $uploadOk = 0;

    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";

echo "C:\Documents and settings\guest\documents\test.txt"; //get full path 
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }
    ?>

0 个答案:

没有答案