Help with Upload script!

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Tue Feb 03, 2004 10:40 pm    Post subject: Help with Upload script! Reply with quote

Edit: I have re written this PHP script and it works , I
still don't know what caused it but I added the fixed
version to this topic at the bottom of the bad one. 8)

I am trying to get this upload PHP script to work that I copied
from my book so I can try and learn a little PHP Uploading.
I get a Undefined error on line 2 , can someone help me fix this

The Following is set:

Register Globals = On
Allow File Uploads = On

Error One:
Code:

<?php
if ($File) {
    print ("File name: $File_name<P>\n");
    print ("File size: $File_size<P>\n");
    if (copy ($File, "users/$File_name")) {
        print ("Your file was successfully uploaded!<P>\n");

} else {

    print ("Your file could not be
    copied<P>\n");

}

unlink ($File);

}

print ("Upload a file to the server:\n");
print ("<FORM ACTION='FileUpload.php'
METHOD='POST' ENCTYPE='multipart/form-
data'>\n");

print ("File <INPUT TYPE='file'
NAME='file' SIZE='20'><BR>\n");

print ("<INPUT TYPE='SUBMIT' NAME=
'submit' VALUE='Submit!'></FORM>\n");
?>


Fixed One:
Code:
<?php
/* This is a basic upload script */
if ($file){
print ("File name: $file_name<p>\n");
print ("File size: $file_size<p>\n");
if (copy ($file, "C:\users/$file_name")){
   print ("Your file was successfully uploaded!<p>\n");
}else{
   print ("Your file was not uploaded!<p>\n");
}
unlink ($file);
}
print ("Upload a file to our server:\n");
print ("<form action=\"file_upload.php\" method=\"post\"
enctype=\"multipart/form-data\">\n");
print ("File <input type=\"file\" name=\"file\"><br>\n");
print ("<input type=\"submit\" name=\"submit\" value=\"Submit\"></form>\n");
?>


Last edited by TRUSTAbyss on Tue Feb 10, 2004 8:35 pm; edited 2 times in total
Back to top View user's profile Send private message Visit poster's website
some random person
-


Joined: 06 Oct 2003
Posts: 128
Location: I live here! At my house!

PostPosted: Tue Feb 03, 2004 11:03 pm    Post subject: Reply with quote

Well $file, and a few other variables arn't defined in your script.
Are you sure you copied the entire script?
_________________
New image comming soon...

Image hosted by abyss powered website
Image copyright some random person (I made it......)
Abyss > Apache (Meaning abyss is better than apache)
My site powered by abyss->(Undergoing construction)
Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Tue Feb 03, 2004 11:21 pm    Post subject: Reply with quote

Yes im sure !
Back to top View user's profile Send private message Visit poster's website
some random person
-


Joined: 06 Oct 2003
Posts: 128
Location: I live here! At my house!

PostPosted: Wed Feb 04, 2004 12:42 am    Post subject: Reply with quote

Well I can't get it... Really havn't done much with uploading. If you want, go here for the manual on file uploads.
Edit: almost got it... Heres what I have:
Code:
<?php
error_reporting(E_ALL & ~E_NOTICE);

$page = $_GET['page'];

if($page == "upload")
{

$File = $_FILES['userfile']['name'];
$File_size = $_FILES['userfile']['size'];
$File_name = $_FILES['userfile']['name'];
if (is_uploaded_file($File))
{
echo "This file is already in the directory";
}
else {
move_uploaded_file($_FILES['userfile']['tmp_name'], $File);
    print ("File name: $File_name<P>\n");
    print ("File size: $File_size<P>\n");
if(is_uploaded_file($File)) {echo "File" . $_FILES['userfile']['name'] . "uploaded";} else {echo "The upload failed";}
}


}

elseif($page == "")
{
print('
<form enctype=multipart/form-data action=test45.php?page=upload method=post>
 <input type=hidden name=MAX_FILE_SIZE value=30000 />
 Send this file: <input name=userfile type=file />
 <input type=submit value=Send File />
</form>');
}
?>

_________________
New image comming soon...

Image hosted by abyss powered website
Image copyright some random person (I made it......)
Abyss > Apache (Meaning abyss is better than apache)
My site powered by abyss->(Undergoing construction)
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group