开发者

HTML form for PHP file upload: no textbox

开发者 https://www.devze.com 2023-01-25 17:24 出处:网络
My PHP book gives a template HTML form for uploading a file: <form action=\"upload.php\" method=\"post\" enctype=\"multipart/form-data\"/>

My PHP book gives a template HTML form for uploading a file:

<form action="upload.php" method="post" enctype="multipart/form-data"/>
    <div>
        <input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
        <label for="userfile">Upload a file:</label>
        <input type="file" name="userfile" id="userfile"/>
        <input type="submit" value="Send File"/>
    </div>
</form>

The book displays it as "Upload a file:" [textbox] [Browse...] [Send File]

I copied it verbat开发者_如何学Pythonim, and the result I'm getting is "Upload a file:" [Choose File] "no file chosen" [Send File]

I'm wondering why the discrepancy exists. Is there a way around it? I'm using XHTML Transitional. No doctype is given in the book. But I doubt that's the issue.

The script I'm writing aims to take the file the user chooses, process it, and write the result into another file that doesn't exist yet. I'm asking this question because it would be useful to let the user more easily copy the initial file path/name, paste it into the other field, and just change a part of it.

(Also: why the difference between "Browse..." and "Choose File"? I tried manually setting the value of the "userfile" field to "Browse..." but nothing happened. This is less important but I'm curious nonetheless.)


It is probably showing a different browser and/or version.

It sounds like you are looking at it under Safari and the book has screenshots of IE, for example.

There are a few ways to get complete control of file uploading and the <input type="file" /> element. You can use Flash, or you can set the input to opacity: 0 and then position what you want beneath it.


Some time ago the browser engines took almost complete control over the input type="file" - fields, since it nowadays is regarded as a security issue. For example the days before that you could easily prefill the file input filed with some path and filename (e.g. something like /etc/passwd) and hide the field, so sending the form you would not remark that you're also sending the file... That's why for example you could not preset the filename of such a field and that's also why browsers now all do their own thing with these special input fields. As Alex said above, you could get around this, but it will be some hassle, because it would mean to "fake" the file input field.

0

精彩评论

暂无评论...
验证码 换一张
取 消