PDA

View Full Version : [Uploader] [CODE]



Jack!
09-06-2008, 03:49 PM
Hi just thought ild ad this its a code for a uploader like justupload or sumthing but better ;)


<?php
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv
// You may change maxsize, and allowable upload file types.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
//Mmaximum file size. You may increase or decrease.
$MAX_SIZE = 200000;

//Allowable file ext. names. you may add more extension names.
$FILE_EXTS = array('.zip','.jpg','.png','.gif','.zip','.mp3','. doc','.css','.htm','.html');
//Allow file delete? no, if only allow upload only
$DELETABLE =no;

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv
// Do not touch the below if you are not confident.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
/************************************************** **********
* Setup variables
************************************************** **********/
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER (http://&quot;.$_SERVER)['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER (http://&quot;.$_SERVER)['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "files/";
$upload_url = $url_dir."/files/";
$message ="Uploading .....Done";
/************************************************** **********
* Create Upload Directory
************************************************** **********/
if (!is_dir("files")) {
if (!mkdir($upload_dir))
die ("upload_files directory doesn't exist and creation failed");
if (!chmod($upload_dir,0755))
die ("change permission to 755 failed.");
}
/************************************************** **********
* Process User's Request
************************************************** **********/
if ($_REQUEST[del] && $DELETABLE) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."DELETE - $_SERVER[REMOTE_ADDR]"."$_REQUEST[del]\n");
fclose($resource);

if (strpos($_REQUEST[del],"/.")>0); //possible hacking
else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking
else if (substr($_REQUEST[del],0,6)==$upload_dir) {
unlink($_REQUEST[del]);
print "<script>window.location.href='$url_this?message=deleted successfully'</script>";
}
}
else if ($_FILES['userfile']) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."UPLOAD - $_SERVER[REMOTE_ADDR]"
.$_FILES['userfile']['name']." "
.$_FILES['userfile']['type']."\n");
fclose($resource);
$file_type = $_FILES['userfile']['type'];
$file_name = $_FILES['userfile']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
//File Size Check
if ( $_FILES['userfile']['size'] > $MAX_SIZE)
$message = "The file size is over 2MB.";
//File Extension Check
else if (!in_array($file_ext, $FILE_EXTS))
$message = "Sorry, $file_name($file_type) is not allowed to be uploaded.";
else
$message = do_upload($upload_dir, $upload_url);

print "<script>window.location.href='$url_this?message=$message'</script>";
}
else if (!$_FILES['userfile']);
else
$message = "Invalid File Specified.";
/************************************************** **********
* List Files
************************************************** **********/
$handle=opendir($upload_dir);
$filelist = "";
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "<a href='$upload_dir$file'>".$file."</a> - URL: <b>$upload_url$file</b>";
if ($DELETABLE)

$filelist .= " Added at ".date("d-m H:i", filemtime($upload_dir.$file))
."";
$filelist .= " <a style='text-decoration:none; font-weight:bold' href='?del=$upload_dir".urlencode($file)."' title='delete'>x</a>";
$filelist .="<br>";
}
}
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_name = str_replace("\\","",$file_name (file://\\","",$file_name));
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0777))
$message = "change permission to 777 failed.";
else
$message = ($result)?"$file_name was uploaded successfully." :
"Something is wrong with uploading the file.";
return $message;
}
?>

<html>
<head>
<title>Uploader - Habboxfroum.com -2fast2kwl</title>
<link rel=stylesheet href=style.css>
</head>
<body>
<br><br>
<center>

<font color=red><?=$_REQUEST[message]?></font>
<br>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Upload File <input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>

<br><b><u>Uploaded files</b></u><br><br>
<?=$filelist?>
</sup></small>
</center>

Independent
09-06-2008, 03:53 PM
Hi just thought ild ad this its a code for a uploader like justupload or sumthing but better ;)


<?php
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv
// You may change maxsize, and allowable upload file types.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
//Mmaximum file size. You may increase or decrease.
$MAX_SIZE = 200000;

//Allowable file ext. names. you may add more extension names.
$FILE_EXTS = array('.zip','.jpg','.png','.gif','.zip','.mp3','. doc','.css','.htm','.html');
//Allow file delete? no, if only allow upload only
$DELETABLE =no;

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv
// Do not touch the below if you are not confident.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
/************************************************** **********
* Setup variables
************************************************** **********/
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER (http://&quot;.$_SERVER)['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER (http://&quot;.$_SERVER)['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "files/";
$upload_url = $url_dir."/files/";
$message ="Uploading .....Done";
/************************************************** **********
* Create Upload Directory
************************************************** **********/
if (!is_dir("files")) {
if (!mkdir($upload_dir))
die ("upload_files directory doesn't exist and creation failed");
if (!chmod($upload_dir,0755))
die ("change permission to 755 failed.");
}
/************************************************** **********
* Process User's Request
************************************************** **********/
if ($_REQUEST[del] && $DELETABLE) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."DELETE - $_SERVER[REMOTE_ADDR]"."$_REQUEST[del]\n");
fclose($resource);

if (strpos($_REQUEST[del],"/.")>0); //possible hacking
else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking
else if (substr($_REQUEST[del],0,6)==$upload_dir) {
unlink($_REQUEST[del]);
print "<script>window.location.href='$url_this?message=deleted successfully'</script>";
}
}
else if ($_FILES['userfile']) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."UPLOAD - $_SERVER[REMOTE_ADDR]"
.$_FILES['userfile']['name']." "
.$_FILES['userfile']['type']."\n");
fclose($resource);
$file_type = $_FILES['userfile']['type'];
$file_name = $_FILES['userfile']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
//File Size Check
if ( $_FILES['userfile']['size'] > $MAX_SIZE)
$message = "The file size is over 2MB.";
//File Extension Check
else if (!in_array($file_ext, $FILE_EXTS))
$message = "Sorry, $file_name($file_type) is not allowed to be uploaded.";
else
$message = do_upload($upload_dir, $upload_url);

print "<script>window.location.href='$url_this?message=$message'</script>";
}
else if (!$_FILES['userfile']);
else
$message = "Invalid File Specified.";
/************************************************** **********
* List Files
************************************************** **********/
$handle=opendir($upload_dir);
$filelist = "";
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "<a href='$upload_dir$file'>".$file."</a> - URL: <b>$upload_url$file</b>";
if ($DELETABLE)

$filelist .= " Added at ".date("d-m H:i", filemtime($upload_dir.$file))
."";
$filelist .= " <a style='text-decoration:none; font-weight:bold' href='?del=$upload_dir".urlencode($file)."' title='delete'>x</a>";
$filelist .="<br>";
}
}
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_name = str_replace("\\","",$file_name (file://%5C%5C%22,%22%22,$file_name));
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0777))
$message = "change permission to 777 failed.";
else
$message = ($result)?"$file_name was uploaded successfully." :
"Something is wrong with uploading the file.";
return $message;
}
?>

<html>
<head>
<title>Uploader - Habboxfroum.com -2fast2kwl</title>
<link rel=stylesheet href=style.css>
</head>
<body>
<br><br>
<center>

<font color=red><?=$_REQUEST[message]?></font>
<br>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Upload File <input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>

<br><b><u>Uploaded files</b></u><br><br>
<?=$filelist?>
</sup></small>
</center>

You've nicked that from another forum.

Decode
09-06-2008, 04:06 PM
You've nicked that from another forum.
Yeah, he needs to give credit to who ever made that.

Pazza
09-06-2008, 04:12 PM
Yeah, he needs to give credit to who ever made that.
Beat me too it.

Anyway, I won't be needing it :(

Jack!
09-06-2008, 04:14 PM
i neva said i made it and i would give credit but i foget who and where i got it from

SORRY :)

Independent
09-06-2008, 04:20 PM
i neva said i made it and i would give credit but i foget who and where i got it from

SORRY :)
You should have at least said you didn't make it.

Meti
09-06-2008, 05:52 PM
it's allright. But who wants a uploader which shows what other people has uploaded?

Agnostic Bear
09-06-2008, 06:18 PM
Hi just thought ild ad this its a code for a uploader like justupload or sumthing but better ;)


<?php
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv
// You may change maxsize, and allowable upload file types.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
//Mmaximum file size. You may increase or decrease.
$MAX_SIZE = 200000;

//Allowable file ext. names. you may add more extension names.
$FILE_EXTS = array('.zip','.jpg','.png','.gif','.zip','.mp3','. doc','.css','.htm','.html');
//Allow file delete? no, if only allow upload only
$DELETABLE =no;

//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv
// Do not touch the below if you are not confident.
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^
/************************************************** **********
* Setup variables
************************************************** **********/
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER (http://&quot;.$_SERVER)['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER (http://&quot;.$_SERVER)['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "files/";
$upload_url = $url_dir."/files/";
$message ="Uploading .....Done";
/************************************************** **********
* Create Upload Directory
************************************************** **********/
if (!is_dir("files")) {
if (!mkdir($upload_dir))
die ("upload_files directory doesn't exist and creation failed");
if (!chmod($upload_dir,0755))
die ("change permission to 755 failed.");
}
/************************************************** **********
* Process User's Request
************************************************** **********/
if ($_REQUEST[del] && $DELETABLE) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."DELETE - $_SERVER[REMOTE_ADDR]"."$_REQUEST[del]\n");
fclose($resource);

if (strpos($_REQUEST[del],"/.")>0); //possible hacking
else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking
else if (substr($_REQUEST[del],0,6)==$upload_dir) {
unlink($_REQUEST[del]);
print "<script>window.location.href='$url_this?message=deleted successfully'</script>";
}
}
else if ($_FILES['userfile']) {
$resource = fopen("log.txt","a");
fwrite($resource,date("Ymd h:i:s")."UPLOAD - $_SERVER[REMOTE_ADDR]"
.$_FILES['userfile']['name']." "
.$_FILES['userfile']['type']."\n");
fclose($resource);
$file_type = $_FILES['userfile']['type'];
$file_name = $_FILES['userfile']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
//File Size Check
if ( $_FILES['userfile']['size'] > $MAX_SIZE)
$message = "The file size is over 2MB.";
//File Extension Check
else if (!in_array($file_ext, $FILE_EXTS))
$message = "Sorry, $file_name($file_type) is not allowed to be uploaded.";
else
$message = do_upload($upload_dir, $upload_url);

print "<script>window.location.href='$url_this?message=$message'</script>";
}
else if (!$_FILES['userfile']);
else
$message = "Invalid File Specified.";
/************************************************** **********
* List Files
************************************************** **********/
$handle=opendir($upload_dir);
$filelist = "";
while ($file = readdir($handle)) {
if(!is_dir($file) && !is_link($file)) {
$filelist .= "<a href='$upload_dir$file'>".$file."</a> - URL: <b>$upload_url$file</b>";
if ($DELETABLE)

$filelist .= " Added at ".date("d-m H:i", filemtime($upload_dir.$file))
."";
$filelist .= " <a style='text-decoration:none; font-weight:bold' href='?del=$upload_dir".urlencode($file)."' title='delete'>x</a>";
$filelist .="<br>";
}
}
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['userfile']['tmp_name'];
$file_name = $_FILES['userfile']['name'];
$file_name = str_replace("\\","",$file_name (file://%5C%5C%22,%22%22,$file_name));
$file_name = str_replace("'","",$file_name);
$file_path = $upload_dir.$file_name;
//File Name Check
if ( $file_name =="") {
$message = "Invalid File Name Specified";
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
if (!chmod($file_path,0777))
$message = "change permission to 777 failed.";
else
$message = ($result)?"$file_name was uploaded successfully." :
"Something is wrong with uploading the file.";
return $message;
}
?>

<html>
<head>
<title>Uploader - Habboxfroum.com -2fast2kwl</title>
<link rel=stylesheet href=style.css>
</head>
<body>
<br><br>
<center>

<font color=red><?=$_REQUEST[message]?></font>
<br>
<form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
Upload File <input type="file" id="userfile" name="userfile">
<input type="submit" name="upload" value="Upload">
</form>

<br><b><u>Uploaded files</b></u><br><br>
<?=$filelist?>
</sup></small>
</center>

Not even reading it, invalid HTML, non strict PHP also it's crap coding.

Independent
11-06-2008, 07:01 AM
Not even reading it, invalid HTML, non strict PHP also it's crap coding.
You mean strict xHTML,

xHTML (Valid) is just a waste of time.

Agnostic Bear
11-06-2008, 11:13 AM
You mean strict xHTML,

xHTML (Valid) is just a waste of time.

No I mean strict PHP, when I use terms I don't get them wrong so it's probably better to just not waste your time correcting me :8

Independent
11-06-2008, 11:16 AM
No I mean strict PHP, when I use terms I don't get them wrong so it's probably better to just not waste your time correcting me :8
I meant do you mean strict XHTML because you said Invalid HTML, I wasn't correcting

Decode
11-06-2008, 11:22 AM
I meant do you mean strict XHTML because you said Invalid HTML, I wasn't correcting
At the top of the page it just says <html> not <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> so the browser should think its HTML 4.0 (i think lol)

off topic: why arnt u in school today ;)

Independent
11-06-2008, 11:27 AM
At the top of the page it just says <html> not <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> so the browser should think its HTML 4.0 (i think lol)

off topic: why arnt u in school today ;)
If you meant me, ill.

on-topic: I'm lazy and I use functions for the headers ;)

Dentafrice
11-06-2008, 12:10 PM
You mean strict xHTML,

xHTML (Valid) is just a waste of time.

You are really getting on my nerves, thinking you know something.

Valid xHTML is not a waste of time, I just believe that you don't actually know what it is, and how to use it.


I meant do you mean strict XHTML because you said Invalid HTML, I wasn't correcting

There is a difference, strict/invalid xHTML or strict/invalid HTML, you could go on an on.

Independent
11-06-2008, 01:02 PM
You are really getting on my nerves, thinking you know something.

Valid xHTML is not a waste of time, I just believe that you don't actually know what it is, and how to use it.



There is a difference, strict/invalid xHTML or strict/invalid HTML, you could go on an on.
Nah, if you take a look it's just a ribbon that you can add to a page (Well a different shape obviously w3)

frontpage / dreamweaver doesn't produce valid xHTML, so IMO it's not worth the time of changing all the code to valid xHTML.

Agnostic Bear
11-06-2008, 01:06 PM
Nah, if you take a look it's just a ribbon that you can add to a page (Well a different shape obviously w3)

frontpage / dreamweaver doesn't produce valid xHTML, so IMO it's not worth the time of changing all the code to valid xHTML.

It is worth it, browsers render valid code faster than invalid code. And you can use xml if you want.

Independent
11-06-2008, 01:07 PM
It is worth it, browsers render valid code faster than invalid code. And you can use xml if you want.
I never knew that.

Dentafrice
11-06-2008, 02:02 PM
#1, Frontpage sucks and is outdated.

#2, Dreamweaver does.. unless you have edited the template.

Agnostic Bear
11-06-2008, 02:43 PM
#1, Frontpage sucks and is outdated.

#2, Dreamweaver does.. unless you have edited the template.

Expression Web 2 is the way to go :8

Dentafrice
11-06-2008, 02:45 PM
It drives me crazy when you try and integrate it with PHP, as the encoding is always ****** up.

Want to hide these adverts? Register an account for free!