Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums Tutorials simple upload (w/ pass protection)
Calamity
Posted on 22 Apr 2008, 02:07:46

Access: Member
Total Posts: 33
Joined: 2008-04-11

Okay.. i know this guy... that had an upload script that had a password protection... and i asked him for the script.. and he wouldn't release it... so recently i remembered about it.. and decided..to attempt to make one... I was talking with Chris and he he gave me permission to mess with it.. (He actually said, "Kurisu says: you could do whatever you want with it. Kurisu says: its free code.) So i was looking around and found a normal upload script and took the $name part of the simple login script and put them together..

Here is the script.. [Name this upload.php (or w/e)

Code:

<?php
session_start
();
$pass[] = "123456";
#create an array of passwords
#add as many as you want

#used for the logout link, changes the session 'loggedin' = false if ?action=logout
if($_GET['action'] == "logout"){
  
$_SESSION['loggedin'] = false;
  
$_SESSION['username'] = "";
}

if(
$_SESSION['loggedin'] == false){ #checks if the user isnt logged in
   
if(!$_POST['s1']){     #checks if the form has been submitted, if not show it
   
}else{
     
#username check
     
$tmppass = $_POST['pass']; #the password the user has submitted
     
$t = count($pass); #count the total passwords
     
$i = 0;
#create a loop to go through each password and compare it with the name pass which was submitted
     
while($i <= $t){
       if(
$tmppass !== ""){
        if(
$tmppass == $pass[$i]){

          
$_SESSION['loggedin'] = true;
          
header('Location: ?'); #reload the page
          
}
        }
      
$i++;
     }
    echo 
"Invalid password 0.o"; #show an error message if the user enters an incorrect pass
   
}
die;
}
?>
<?php 
$target 
= "upload/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 

//This is our size condition 
if ($uploaded_size > 350000000) 
{ 
echo 
"Your file is too large.<br>"; 
$ok=0; 
} 

//This is our limit file type condition 
if ($uploaded_type =="text/php") 
{ 
echo 
"No PHP files<br>"; 
$ok=0; 
} 

//Here we check that $ok was not set to 0 by an error 
if ($ok==0) 
{ 
Echo 
"Sorry your file was not uploaded"; 
} 

//If everything is ok we try to upload it 
else 
{ 
if(
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{ 
echo 
"The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
} 
else 
{ 
echo 
"Sorry, there was a problem uploading your file."; 
}
}
?>


Then what you wanna do is.. add this script to a page and change the path to the script above...

ALSO-- if you would like to upload files of bigger size change the number found here

Code:

if ($uploaded_size > 350000000)


Code:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input name="uploaded" type="file" size="30">
<br><br>
<input type="password" name="pass" size="32">
<input type=submit name="s1" value="Upload">
</form>

to change the size of the text area things mess with the numbers inside size="" [of course the higher the bigger]
----

If you would like this with out the password feature.. go back to PHP Tutorials and look for the post called Simple Upload Form

-Tyler
#177
Last edited by Calamity at 2008-04-22 02:12:34 Reason:
Network-13.com © 2013