Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache on Windows: how to set up an upload

Status
Not open for further replies.

cheerful

Programmer
Mar 4, 2003
173
0
0
US
I would like to have simple upload w/ Apache on Windows. The intent is able to upload a file via HTTP protocol. I have Apache installed and running. What is the easiet way to set it up?

Thanks!
 
Simple - Open a text editor such as notepad or your favourite one and paste the following:

<html>
<head>
<title>file upload form</title>
</head>
<body>
<form action="upload.php" enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
File to Upload: <input type="file" name="fileupload"><br><br>
<input type="submit" value="upload!">
</form>
</body>
</html>

Name this index.php and place it in a folder named "file"

Next open a new text editor page and paste this:

<html>
<head>
<title>Results of Upload</title>
</head>
<body>
<h1>File Upload Results</h1>
<?php
$file_dir = "C:\location of your file folder (you need to change this....";

foreach($_FILES as $file_name => $file_array) {
print "path: ".$file_array['tmp_name']."<br>\n";
print "name: ".$file_array['name']."<br>\n";
print "type: ".$file_array['type']."<br>\n";
print "size: ".$file_array['size']."<br>\n";

if (is_uploaded_file($file_array['tmp_name'])) {
move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Couldn't copy");
print "file was moved!<br><br>";
}
}
?>
</html>

Save this is as upload.php
***************************************

This should work - it works for me...Mind you - make sure to .htaccess your folder. Just an idea.


SeanRadio

 
Newbie on Apache here. How do I install php? Does the module come with Apache? Or sth that I have to download and add to the conf file?

Thanks!
 
Easy!

Stop Apache. net stop apache in command or stop apache using the start menu.
-First, open the configuration file(httpd) - located in the 'conf' folder of Apache

-Search for DirectoryIndex then we will add little extra characters to that line.

-Follow the image below. just add index.php and index.htm after index.html

Next --

Go to the line or search for 'AddType application/x-tar .tgz'
below that line add the following:
-You can cut and paste them.

LoadModule php4_module c:/php/sapi/php4apache.dll
AddType application/x-httpd-php .php


Now close this and save it.

Next download PHP -


Choose your download location & then....

Then unzip this file into the folder 'c:\php'
Note: When you unzip this file, it drops an extra folder.
C:\php\php-blah*. Move the contents of the second php folder to the first one then delete that extra php folder that was created.

Configure PHP
Go into folder 'c:\php' find file 'php.ini-dist' rename it to 'php.ini'
Open the file 'php.ini' using 'Notepad'
Under 'Search' click 'Find' or 'Edit' click 'Find' on Windows 2000 or press 'Ctrl+F'
then type this 'doc_root' - change to the directory of where your site is being held..mying is in c:\web example below:

; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues. The alternate is to use the
; cgi.force_redirect configuration below
doc_root = "c:\web"

Next change the extension_dir to the info below.

; Directory in which the loadable extensions (modules) reside.
extension_dir = "c:\php"

Moving along....


-Save and Close the file.
-Now, lets move this file to:
'php.ini' to c:\windows -- Win95/98/XP
To c:\winnt or c:\winnt40 -- WinNT/2000/XP

copy the file php4apache.dll from c:\php\sapi folder to the apache.exe folder
By default c:\Program Files\Apache Group\Apache

also copy the file php4ts.dll from c:\php to the same apache.exe folder
.....

Ok now for the test!

Open your fav text editor and paste this inside:

Today's date is: <? print (date ("M d, Y")); ?>

save it and call test.php

********

Load the test.php file to your web directory and turn your web server on...and you should be good to go!


Let me know.
 
Looks like quite involved. I probably understand things better before I run everything. Will try it soon.

Thanks everyone!
 
I got it working for small files. I remove the hidden input MAX_FILE_SIZE or set it to sth like 10000000. However, any large file (e.g. 1MB) won't work. Is there some setting to control the upload file size?

Thanks!
 
<input type="hidden" name="MAX_FILE_SIZE" value="20000000">

This works for me. But - as you begin to play with these PHP scripts, you will learn a TON. You need to also edit your PHP.ini file.

Look at:

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
;upload_tmp_dir =

; Maximum allowed size for uploaded files.
upload_max_filesize = 20M


You will need to edit the upload_max_filesize - I use this script for people to upload files daily.

Enjoy!

PS: the PHP.ini file is in C:\WINDOWS - Just make sure to save your changes...
 
OK. found out myself. In php.ini, upload_max_filesize
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top