View previous topic :: View next topic |
Author |
Message |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Sat Apr 17, 2004 8:15 am Post subject: Register Globals = Off | Problem |
|
|
I am having trouble with my upload script and don't ask if I have
tried $_GET , _POST , or $_REQUEST because I tried it all and nothing
seems to work at all , can you help me program my ::File Uploader::
php script to use Register Globals = Off because that would mean alot
to me if you could help me out , Have A Nice Day !
Code: | <html>
<head>
<title>File Uploader</title>
</head>
<body bgcolor="silver">
<?php
$max_size = "1048576"; // Maximum File Size (In Bytes)
$extensions = ".gif$|.jpg$"; // Allowed File Extensions
if ($file) {
if ($file_size <= $max_size) {
if (ereg($extensions , $file_name)) {
print "File name: $file_name<p>\n";
print "File size: $file_size<p>\n";
if (copy ($file, "files_uploaded/$file_name")) {
print "<font color=\"blue\" font size=\"3\">Your file was successfully uploaded !</font><p>\n";
}else{
print "<font color=\"red\" font size=\"3\">Your File could not be uploaded!</font></P>\n";
}
}else{
print "<font color=\"red\" font size=\"3\">Bad File Extension (GIF & JPG) Only!</font><p>\n";
}
}else{
print "<font color=\"red\" font size=\"3\">The File Size is Too Big!</font><p>\n";
}
unlink ($file);
}
print "Upload a File to the server:
<br><form action='index.php' method='post' enctype='multipart/form-data'>
<input type='file' name='file'><br><input type='submit' value='Upload'><br>
<hr>Files Allowed: GIF and JPG <br> Max File Size: 1 MB";
?>
</body>
</html>
|
|
|
Back to top |
|
 |
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Sun Apr 18, 2004 4:44 pm Post subject: Re: Register Globals = Off | Problem |
|
|
TRUSTpunk,
You must replace $file and the other upload variables with their equivalent as explained in http://us4.php.net/features.file-upload (for example, $_FILES['file']['name']). _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
 |
some random person -
Joined: 06 Oct 2003 Posts: 128 Location: I live here! At my house!
|
Posted: Sun Apr 18, 2004 6:57 pm Post subject: |
|
|
Also, for the submit button you should give it a name. Like <input type='submit' value='Upload' name='upload'>
Then change if($file) to if(isset($_REQUEST['upload']))
Thats how I did it. _________________ 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 |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Mon Apr 19, 2004 3:26 am Post subject: |
|
|
Why do php.net have to make programming
so irritating lol , I will try that and if it doesn't
work , I would like someone to post the code.
I was able to get the variables registered but
the unlink feature does not work with this new
code , anybody know why unlink() will not work
Updated Code (its alot lol)
Code: | <html>
<head>
<title>File Uploader</title>
</head>
<body bgcolor="silver">
<?php
ini_set("display_errors", 1);
error_reporting(E_ALL & ~E_NOTICE);
$file = $_FILES['file'];
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$max_size = "1048576"; // Maximum File Size (In Bytes)
$extensions = ".gif$|.jpg$"; // Allowed File Extensions
if ($file) {
if ($file_size <= $max_size) {
if (ereg($extensions , $file_name)) {
print "File name: $file_name<p>\n";
print "File size: $file_size<p>\n";
if (copy ($file, "files_uploaded/$file_name")) {
print "<font color=\"blue\" font size=\"3\">Your file was successfully uploaded !</font><p>\n";
}else{
print "<font color=\"red\" font size=\"3\">Your File could not be uploaded!</font></P>\n";
}
}else{
print "<font color=\"red\" font size=\"3\">Bad File Extension (GIF & JPG) Only!</font><p>\n";
}
}else{
print "<font color=\"red\" font size=\"3\">The File Size is Too Big!</font><p>\n";
}
unlink ($file);
}
print "Upload a File to the server:
<br><form action='index.php' method='post' enctype='multipart/form-data'>
<input type='file' name='file'><br><input type='submit' value='Upload'><br>
<hr>Files Allowed: GIF and JPG <br> Max File Size: 1 MB";
?>
</body>
</html>
|
This will display errors in the code when you upload a valid file
and will tell you warning , cannot copy or something like that.
Here it is !
Code: | Warning: unlink(Array): No such file or directory in C:\Program Files\Abyss Web Server\htdocs\php-scripts\index.php on line 30
|
|
|
Back to top |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Tue Apr 20, 2004 10:36 am Post subject: |
|
|
I fixed it by using a different copying method
in PHP , I used move_uploaded_file() , thanks
for all the awesome support , LateR! 8) |
|
Back to top |
|
 |
|