1

I want user must upload file from his/her C drive,they cant upload file from other drive.

My upload code is here.

<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="filename" />
<input type="submit" value="Upload" />
</form>

And

$file_name = $_FILES['fupload']['name'];

$file_type = $_FILES['fupload']['type'];

print "Path: ".$_FILES['fupload']['tmp_name']."<br />";

print "Name: $file_name <br />";

print "Size: ".$_FILES['fupload']['size']."<br />";

print "Type: $file_type <br />";

if(copy($_FILES['fupload']['tmp_name'], "$file_name"))
{
    print "Upload Success";
}
else
{
    print "Error occur";
}
2
  • 1
    Definitely not possible... Commented Jan 23, 2013 at 7:14
  • What is the motivation for this? Why are you interested in where the user has stored a file he uploads? And: keep in mind that something like "a C drive" only exists on MS-Windows systems. All other operating systems have a more modern, flexible and logical layout of the local file system. Commented Jan 23, 2013 at 7:23

4 Answers 4

1

It's not possible to force user upload file from specific drive.

Check out this link from php.net: $_FILES

These are all you can know about the uploaded file:

 [name] => 400.png // file name
 [type] => image/png // file type
 [tmp_name] => /tmp/php5Wx0aJ // file temp name
 [error] => 0 // file uploading error
 [size] => 15726 // file size

For JavaScript you can see this question: Javascript: Listing File and Folder Structure

Sign up to request clarification or add additional context in comments.

4 Comments

is it possible to get user file upload directory like C://file.txt
is it possible with jscript??
@AshekurRahmanmollaAsik: once and for all: NO! Out of security and privacy reasons you have NO control over the client sites file picking process. If you would find a way that would be a massive security thread, a browser bug to be fixed as soon as possible.
it is possible just see my answer, Thanks
0

You can do what you want if you can get the absolute path of the file. If you can get the absolute path of the file, you can do a simple equality test if the path is not "C:\".

But the built-in input type file will not give you any hint on this as it is for security purposes.

If you can make your own upload form then you can but using the input type file it is impossible.

Comments

0

You can write/use a Java Applet that handles the upload on the client side. There you can check the actual file path. But that won't help you if a user just copies a file to C: before uploading it. I don't see any point in trying this.

Just with HTML/JavaScript/PHP it is not possible.

Comments

0
This is only possible IE.


<head>
    <script type="text/javascript">
        function CheckAndSubmit () {
            var uploadForm = document.getElementById ("uploadForm");
            var uploadFile = document.getElementById ("uploadFile");
            var fileinfo = document.getElementById ("fileloc");

            if (uploadFile.value.length == 0) {
                alert ("Please specify the path to the file to upload!");
                return;
            }
            //alert(document.uploadForm.uploadFile.value);

            fileinfo.value=uploadFile.value;


            uploadForm.submit ();
        }
    </script>
</head>
<body>
    <?php
        //if(isset($_POST['uploadFile']))
            print_r($_POST);
    ?>
    <form id="uploadForm" name="uploadForm" method="post" enctype="multipart/form-data" action="">
        Select a file: <input type="file" name="uploadFile" id="uploadFile" size="25" />
        <input type="hidden" id="fileloc" name="fileloc" value="" />
        <br /><br />
        <input type="button" value="Upload" onclick="CheckAndSubmit ()"/>
    </form>
</body>

If not shown full path>> 1. open internet Explorer internet option>security>custom level> 2. Then Enable include local directory file path when uploading....

Enjoy...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.