PHP Upload File

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bmartling
Forum Newbie
Posts: 2
Joined: Wed Feb 07, 2007 7:16 pm

PHP Upload File

Post by bmartling »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I've read a lot of posts, but I can't find the answer to my problem. I'm a php newbie, so please bear with me (I've been programming for 25 years in other languages - mostly MS - VB, ASP, etc). I copied the examples from the php manual to upload a file, but I get a dialog box asking to save or open my php page ('uploader.php') that's supposed to process the post from the upload form. I know my config is wrong somehow, but most of my php stuff works, so why not this?

Here's my select file to upload page ('upload.htm')

[syntax="html"]<html>
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="uploader.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>
</html>
And here's my processor page: ('uploader.php'):[/syntax]

Code: Select all

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = './UPLOADS/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

bmartling wrote:but I get a dialog box asking to save or open my php page ('uploader.php')
You're requesting the document via http://localhost/uploader.php ?
Is your webserver configured to let php hande the request?
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post by jyhm »

Sometimes I get that same dialog box when posting on these forums. I hit post and the page lags for a while, then asks me if I want to save post.php . :?

It only happens once and a while so I ignore it, but I have no idea why it does this.
bmartling
Forum Newbie
Posts: 2
Joined: Wed Feb 07, 2007 7:16 pm

reply

Post by bmartling »

That's the question. My php bulletin board works - so php is working - up to a point. When a page from my bb links to another php page, it works. But the post from the download doesn't. I've got the cgi dll in my config for my virtual directory, with all verbs activated. Why does it want to save/download this php file, and not others?

IE links (anchors) work, but not posts.

Thanks
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post by jyhm »

Have you tested this remotely as opposed to your locale system?
Post Reply