views:

79

answers:

3

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>
A: 

Perhaps this is the only folder with write-permissions.

Diodeus
I'm doing this all locally using XAMPP so I doubt that would be an issue.
vette982
can you show us a screenshoot of the window
Adnan
You're either not posting the right code or there's something wrong with your computer. That code works well, in fact, I just tested it on my computer and I was able to upload files from different directories. Please show your screenshot as suggested by @Adnan
Helen Neely
A: 

I guess it is jquery that is doing the actual posting to http://imgur.com/api/upload as the form is just posting to itself, so my guess is that jquery / javascript can only read files in your web-space and not on your whole hard-drive.

jeroen
+2  A: 

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.

Marc B
"Dont' work to well" is an understatement! hehe
Diodeus
Ya. It won't work __at all__.
George Edison