简体   繁体   中英

HTML Upload Form will only upload files found in the directory of the PHP file

I have an image uploader that uses the imgur.com API and jQuery's .ajax() function to upload images to their servers. However, if I browse for an image using the <input type="file"/> element of the form, it will only be successful in uploading an image if the image file is found in the same directory as the page.php file that the form is found in (shown below). How can I allow the form to upload images from any directory on my computer?

page.php:

<form action="page.php" method="post">
    <input type="file" name="doc" id="doc" /><br/>
    <input type="image" src="go.gif" name="submit" id="submit" />
</form>

You've forgotten the enctype="multipart/form-data" attribute on your form tag, for one. Without that, file uploads generally don't work too well.

Beyond that, the server won't really care what directory you're uploading FROM, especially under PHP. The uploaded copy on the server is stored with temporary filename ( $_FILES['file']['tmp_name'] ) that has absolutely nothing to do with the directory/filename on your computer.

Once it's on the server, you'll have to actually move that temporary file somewhere else, as PHP will auto-delete it once the script terminates and you've not handled it yourself. move_uploaded_file() is what's generally used to take of that process.

也许这是唯一具有写权限的文件夹。

我猜是jquery正在实际发布到http://imgur.com/api/upload因为表单只是在向自身发布,所以我猜jquery / javascript只能读取您的网站空间中的文件,不在整个硬盘上。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM