 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
deleted user 111213 Grandmaster Cheater
Reputation: 0
Joined: 09 Nov 2007 Posts: 714
|
Posted: Thu Mar 26, 2009 9:20 am Post subject: [HELP] PHP File upload system |
|
|
i have gone through the code several times, i can't find what is wrong with it. sometimes i get an error to say check that the folder is chmod 777. or it just takes the piss(takes forever) to upload. and then it doesn't upload.
here is my code. please bear in mind it is powered by phUploader.
| Code: | <?
error_reporting(7);
$max_file_size="50000";
$max_combined_size="150000";
$file_uploads="3";
$websitename="Upload";
$random_name=false;
$allow_types = array("jpg", "gif", "png", "zip", "rar", "txt", "doc", "exe", "rar", "zip", "swf", "docx", "fla", "flv", "mp4", "psd", "sql", "mp3");
$folder="./uploads/";
$full_url="http://matt.imhotek.net/upload/uploads/";
$fullpath="";
$password="";
$password_md5=md5($password);
If($password) {
If($_POST['verify_password']==true) {
If(md5($_POST['check_password'])==$password_md5) {
setcookie("phUploader",$password_md5,time()+86400);
sleep(1); //seems to help some people.
header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
exit;
}
}
}
$password_form="";
If($password) {
If($_COOKIE['phUploader']!=$password_md5) {
$password_form="<form method=\"POST\" action=\"".$_SERVER['PHP_SELF']."\">\n";
$password_form.="<table align=\"center\" class=\"table\">\n";
$password_form.="<tr>\n";
$password_form.="<td width=\"100%\" class=\"table_header\" colspan=\"2\">Password Required</td>\n";
$password_form.="</tr>\n";
$password_form.="<tr>\n";
$password_form.="<td width=\"35%\" class=\"table_body\">Enter Password:</td>\n";
$password_form.="<td width=\"65%\" class=\"table_body\"><input type=\"password\" name=\"check_password\" /></td>\n";
$password_form.="</tr>\n";
$password_form.="<td colspan=\"2\" align=\"center\" class=\"table_body\">\n";
$password_form.="<input type=\"hidden\" name=\"verify_password\" value=\"true\">\n";
$password_form.="<input type=\"submit\" value=\" Verify Password \" />\n";
$password_form.="</td>\n";
$password_form.="</tr>\n";
$password_form.="</table>\n";
$password_form.="</form>\n";
}
}
function get_ext($key) {
$key=strtolower(substr(strrchr($key, "."), 1));
$key=str_replace("jpeg","jpg",$key);
return $key;
}
$ext_count=count($allow_types);
$i=0;
foreach($allow_types AS $extension) {
If($i <= $ext_count-2) {
$types .="*.".$extension.", ";
} Else {
$types .="*.".$extension;
}
$i++;
}
unset($i,$ext_count);
$error="";
$display_message="";
$uploaded==false;
If($_POST['submit']==true AND !$password_form) {
For($i=0; $i <= $file_uploads-1; $i++) {
If($_FILES['file']['name'][$i]) {
$ext=get_ext($_FILES['file']['name'][$i]);
$size=$_FILES['file']['size'][$i];
$max_bytes=$max_file_size*1024;
If($random_name){
$file_name[$i]= time() + rand(86400)+ 20 .".".$ext;
} Else {
$file_name[$i]=$_FILES['file']['name'][$i];
}
If(!in_array($ext, $allow_types)) {
$error.= "Invalid extension for your file: ".$_FILES['file']['name'][$i].", only ".$types." are allowed.<br />Your file(s) were <b>not</b> uploaded.<br />";
} Elseif($size > $max_bytes) {
$error.= "Your file: ".$_FILES['file']['name'][$i]." is to big. Max file size is ".$max_file_size."kb.<br />Your file(s) were <b>not</b> uploaded.<br />";
} Elseif(file_exists($folder.$file_name[$i])) {
$error.= "The file: ".$_FILES['file']['name'][$i]." exists on this server, please rename your file.<br />Your file(s) were <b>not</b> uploaded.<br />";
}
}
}
$total_size=array_sum($_FILES['file']['size']);
$max_combined_bytes=$max_combined_size*1024;
If($total_size > $max_combined_bytes) {
$error.="The max size allowed for all your files combined is ".$max_combined_size."kb<br />";
}
If($error) {
$display_message=$error;
} Else {
// No errors so lets do some uploading!
For($i=0; $i <= $file_uploads-1; $i++) {
If($_FILES['file']['name'][$i]) {
If(@move_uploaded_file($_FILES['file']['tmp_name'][$i],$folder.$file_name[$i])) {
$uploaded=true;
} Else {
$display_message.="Couldn't copy ".$file_name[$i]." to server, please make sure ".$folder." is chmod 777 and the path is correct.\n";
}
}
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $websitename; ?></title>
<style type="text/css">
body{
background-color:#FFFFFF;
background-image: url(http://matt.imhotek.net/forum/bg.png);
font-family: Verdana, Arial, sans-serif;
font-size: 12pt;
color: #FFFFFF;
}
.error_message{
font-family: Verdana, Arial, sans-serif;
font-size: 11pt;
color: #FF0000;
}
.uploaded_message{
font-family: Verdana, Arial, sans-serif;
font-size: 11pt;
color: #FFFFFF;
}
a:link{
text-decoration:none;
color: #FFFFFF;
}
a:visited{
text-decoration:none;
color: #CC0000;
}
a:hover{
text-decoration:none;
color: #990000;
}
.table {
border-collapse:collapse;
border:1px solid #FFFFFF;
width:450px;
border-left:1px solid #FFFFFF;
}
.table_header{
border:1px solid #FFFFFF;
background-color:#000;
font-family: Verdana, Arial, sans-serif;
font-size: 11pt;
font-weight:bold;
color: #FFFFFF;
text-align:center;
padding:2px;
border-left:1px solid #FFFFFF;
}
.upload_info{
border:1px solid #FFFFFF;
background-color:#000;
font-family: Verdana, Arial, sans-serif;
font-size: 8pt;
color: #FFFFFF;
padding:4px;
}
.table_body{
border:1px solid #FFFFFF;
background-color:#000;
font-family: Verdana, Arial, sans-serif;
font-size: 10pt;
color: #FFFFFF;
padding:2px;
}
.table_footer{
border:1px solid #FFFFFF;
background-color:#000;
text-align:center;
padding:2px;
border-left:1px solid #FFFFFF;
}
input,select,textarea {
font-family: Verdana, Arial, sans-serif;
font-size: 10pt;
color: #000;
background-color:#000;
border:1px solid #FFFFFF;
}
form{
padding:0px;
margin:0px;
}
</style>
<?
If($password_form) {
Echo $password_form;
} Elseif($uploaded==true) {?>
<table align="center"class="table">
<tr>
<td class="table_header" colspan="2"><b>Your file(s) have been uploaded!</b> </td>
</tr>
<tr>
<td class="table_body">
<br />
<?
For($i=0; $i <= $file_uploads-1; $i++) {
If($_FILES['file']['name'][$i]) {
$file=$i+1;
Echo("<b>File #".$file.":</b> <a href=\"".$full_url.$file_name[$i]."\" target=\"_blank\">".$full_url.$file_name[$i]."</a><br /><br />\n");
}
}
?>
<br />
<a href="<?=$_SERVER['PHP_SELF'];?>">Go Back</a>
<br />
</td>
</tr>
</table>
<?} Else {?>
<?If($display_message){?>
<div align="center" class="error_message"><?=$display_message;?></div>
<br />
<?}?>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="phuploader">
<table align="center"class="table">
<tr>
<td class="table_header" colspan="2"><b><?=$websitename;?></b> </td>
</tr>
<tr>
<td colspan="2" class="upload_info">
<b>Allowed Types:</b> <?=$types?><br />
<b>Max size per file:</b> <?=$max_file_size?>kb.<br />
<b>Max size for all files combined:</b> <?=$max_combined_size?>kb.<br />
</td>
</tr>
<?For($i=0;$i <= $file_uploads-1;$i++) {?>
<tr>
<td class="table_body" width="20%"><b>Select File:</b> </td>
<td class="table_body" width="80%"><input type="file" name="file[]" size="30" /></td>
</tr>
<?}?>
<tr>
<td colspan="2" align="center" class="table_footer">
<input type="hidden" name="submit" value="true" />
<input type="submit" value=" Upload File(s) " />
<input type="reset" name="reset" value=" Reset Form " />
</td>
</tr>
</table>
</form>
<? } ?>
</body>
</html> |
i can't find any errors.
|
|
| Back to top |
|
 |
compactwater I post too much
Reputation: 8
Joined: 02 Aug 2006 Posts: 3923
|
Posted: Thu Mar 26, 2009 4:21 pm Post subject: |
|
|
Seems to work fine on my local server.
Use
chmod('./uploads/', 0777);
to set the chmod for that folder, unless you have access to the server.
It seems PHP is having a timeout on long uploads, thus canceling them.
Try adding
set_time_limit(0);
to the top of your code.
|
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Thu Mar 26, 2009 5:41 pm Post subject: |
|
|
You should learn how to use ajax so that you can actually view the upload progress.
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
kittonkicker I post too much
Reputation: 1
Joined: 19 Apr 2006 Posts: 2171
|
Posted: Fri Mar 27, 2009 9:42 am Post subject: |
|
|
Baww that code is ugly >.>. It works for me tho...
_________________
All gone  |
|
| Back to top |
|
 |
|
|
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 You cannot attach files in this forum You can download files in this forum
|
|