Page 1 of 1

PHP Upload File

Posted: Wed Feb 07, 2007 9:02 pm
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]

Posted: Wed Feb 07, 2007 10:05 pm
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?

Posted: Wed Feb 07, 2007 10:20 pm
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.

reply

Posted: Wed Feb 07, 2007 10:44 pm
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

Posted: Wed Feb 07, 2007 11:17 pm
by jyhm
Have you tested this remotely as opposed to your locale system?