Upload Script

wyatt_tsik's picture

He has: 5 posts

Joined: May 2004

Hi guys,

I hope you could help me out on this. I need a script that could upload a file on my website. I found in the net a script that I think could help me, but somehow I cant figure out how the script works.
The attached script below has a problem with uploading a specified file. The script tends to upload the "upload.php" even if you have specified a file to upload.

could you help me guys, pls, thanks in advance!

here's the script codes for the upload.php and demo.htm files:

****upload.php

<?php
//GG NETWORKS FILE UPLOAD SCRIPT

$file = $_POST[file];

$path = "/relative/directory/to/file";     //SET THIS TO THE RELATIVE PATH FROM WHERE THE SCRIPT IS TO WHERE THE FILE SHOULD BE UPLOADED TO,

if($file){
   
    print(
"File name: $file_name<P>/n");
    print(
"File size: $file_size bytes<P>/n");
   
    if(
copy($file, "$path/$filename")){
       
        print(
"Your File was uploaded successfully");
    }else{
        print(
"ERROR, your file was not successfully uploaded");
    }
   
   
unlink($file);
}
?>

****demo.html

Untitled Document

FILE Upload Demo page

File to be uploaded.

 

s0da's picture

He has: 157 posts

Joined: Mar 2004

it's actually $HTTP_POST_FILES and not $_POST

i think that's what you wanted.

wyatt_tsik's picture

He has: 5 posts

Joined: May 2004

Thanks for the response s0da,

do you mean that
$file = $_POST[file]; should be replaced by $HTTP_POST_FILES

I've tried that, didn't work either.

Help again pls.

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

I'm going to move this post to server side scripting (just in the interest of forum cleanliness Smiling)

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

s0da's picture

He has: 157 posts

Joined: Mar 2004

lol it's $HTTP_ or $_FILES . i played it safe just incase he had an old version of PHP.

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

True. I seem to bump into newer versions more than older that won't use the $HTTP_ because it's not set properly for the script. It would have to be a much older version (than 4.1.0) for it not to work.

Regardless, the links provide all the helpful information you should need to get it working. Smiling

wyatt_tsik's picture

He has: 5 posts

Joined: May 2004

Thanks for the response, I really appreciate it. Smiling

Still, the upload.php file are the one that is being uploaded and not the file that I had specified when browsed.

Since I am an amateur in this field, I cant seem to know where the programming of the php (upload.php) or demo.html files got wrong?

Also, is it possible to have the file scanned by an anti-virus apps before saving it to the server? May I also get an advice advice. pls.

Pls help! Sad

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

Did you make changes to your script?

wyatt_tsik's picture

He has: 5 posts

Joined: May 2004

Yes I did. Sad

I have attached the files Im currently working with... pls help Sad

wyatt_tsik's picture

He has: 5 posts

Joined: May 2004

by-the-way, Im using a win2k server

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

http://www.php.net/manual/en/features.file-upload.php#features.file-upload.post-method

ctrl+f for "garyds at miraclemedia dot ca"

Of course, if you're using someone else's script, you should check with the developer first.

Busy's picture

He has: 6,151 posts

Joined: May 2001

That doesn't look like a complete script, the php file is trying to display things like the size etc but you havent asked for them
print("File name: $file_name/n");
print("File size: $file_size bytes/n");

file_name and file_size will always be false (empty) as they aren't assigned a value anywhere.

You also need to set your path, if on web server something like var/site/home or whatever, on localhost (pc) set to your php file directory root.

Your question in post #8, no you can't scan your file with antivirus program, on your own server you can. You can however set limits to what type of files can be uploaded, what size, where from ... play safe, never trust anybody.

you might need to find yourself a better upload script, tried hotscripts.com ?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.