开发者

'Upload' form to grab complete location of file?

I've created a HTML and PHP form to pretty much just input data into a MySQL table.

I've got a file upload field, but it doesn't upload a file. I don't want it to upload anything to the server, all I want is for it to grab the location of the file selected and input that into the database.

It works perfectly fine on Internet Explorer, but doesn't work on any other browser, I assume it's because of security issues it imposes.

My input code:

<input type="file" id="filename" name="filename" />

And of course when the form is submitted some PHP code runs through to insert the data into the database. I've tried JavaScript to copy value of that field to to another field but again because of security issues that doesn't work.

Does anyone know of a way I can do this in JavaScript? Or even Flash? To be honest, anything similar to these would do, just something that works in browsers other than IE.

Thanks.

EDIT -

Here's my code:

<?php
if (isset($_POST['submit'])) {
    $name = addslashes(htmlentities($_POST['name']));
    $filename = addslashes(htmlentities($_POST['filename']));

    if (@mysql_query("INSERT INTO movies SET
                      name='$name',
                      doc_filename='$filename'")) {
        echo '<p>Movie added.</p><p><a href=movies.php">Manage movies</a>.</p>';
    } else {
        echo '<strong>Error:</strong> '.mysql_error().'';
    }
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="newspost" enctype="multipart/form-data">
    <div class="form-row">
        <label for="fm_title">Movie file path: <开发者_JAVA百科;/label><br />
        <input type="file" id="filename" name="filename" />
    </div><br />
    <div class="form-row">
        <label for="fm_title">Movie name: </label><br />
        <input type="text" class="input-width" name="name" value="<?php if (!empty($_POST['name'])) { echo $_POST['name']; } ?>" />
    </div>
    <div class="form-row">
        <input type="submit" name="submit" value="Submit" />
    </div>
</form>
<?php
}
?>


all I want is for it to grab the location of the file selected and input that into the database.

This is no longer possible using HTML - for security reasons, the location of the selected file is not accessible in the file input's DOM element anymore. Most browsers use C:\Fakepath\ instead.

You might be able to get hold of this information using a Flash or Java based uploader (edit: see e.g. this page in the AS3 manual) SWFUpload's API could be worth a look. It could be that you need to build your own Flash or Java solution for this, though.


how you are posting the data of the form? I am not able to see any way of form post. No Submit button or onclick or onchange event of javascript? and also how you suppose this line to give output

<input type="text" class="input-width" name="name" value="<?php if (!empty($_POST['name'])) { echo $_POST['name']; } ?>" />

as its already in else part of the line

if (isset($_POST['submit']))

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜