I got this script from an online source, but I can’t seem to get it to work. I know nothing about php, and the script is giving some errors… Can someone help (I need help fairly quickly, because I am going to use this to be able to transport my files to and from school [floppy disks are soooo obsolete ;)])
the url is here (EDITED)
username: ****
password: **** (edited)
they are supposed to upload to (Edited)
but it’s giving me all sorts of error messages (log on and try to upload a file, you’ll see)
here’s the php script:
<?php
//Username + password
$user = "****"; //edited
$pass = "****"; //edited
//Show the number of files to upload
$files_to_upload = 2;
//Directory where the uploaded files have to come
//RECOMMENDED TO SET ANOTHER DIRECTORY THEN THE DIRECTORY WHERE THIS SCRIPT IS IN!!
$upload_dir = "schoolwork";
// -------------------------------- //
// UPDATE LOG //
// -------------------------------- //
// Version 1.0 -> version 1.1
// - Confirm the deletion of the file
// - Download a file (handy for PHP files ;))
// - Set the number of files to upload
//
// Version 1.1 -> version 1.11
// - Able to rename the files
// -------------------------------- //
// -------------------------------- //
// SCRIPT UNDER THIS LINE! //
// -------------------------------- //
session_start();
//When REGISTERED_GLOBALS are off in php.ini
$_POST = $HTTP_POST_VARS;
$_GET = $HTTP_GET_VARS;
$_SESSION = $HTTP_SESSION_VARS;
//When logging in, check username and password
if($_GET['method'] == "login")
{
if($_POST['username'] == $user && $_POST['password'] == $pass)
{
//Set the session for logged in to true
session_register('logged_in');
$_SESSION['logged_in'] = true;
Header("Location: ".$_SERVER['PHP_SELF']);
}
}
//Any other action the user must be logged in!
elseif($_GET['method'])
{
//When not logged in, the user will be notified with a message
if(!session_is_registered('logged_in'))
{
not_allowed();
exit;
}
session_register('message');
//Upload the file
if($_GET['method'] == "upload")
{
//$file_array = $HTTP_POST_FILES['file'];
$_SESSION['message'] = "";
$uploads = false;
for($i = 0 ; $i < $files_to_upload; $i++)
{
if($_FILES['file']['name'][$i])
{
$uploads = true;
if($_FILES['file']['name'][$i])
{
$file_to_upload = $upload_dir."/".$_FILES['file']['name'][$i];
move_uploaded_file($_FILES['file']['tmp_name'][$i],$file_to_upload);
chmod($file_to_upload,0777);
$_SESSION['message'] .= $_FILES['file']['name'][$i]." uploaded.<br>";
}
}
}
if(!$uploads) $_SESSION['message'] = "No files selected!";
}
//Logout
elseif($_GET['method'] == "logout")
{
session_destroy();
}
//Delete the script
elseif($_GET['method'] == "delete" && $_GET['file'])
{
if(!@unlink($upload_dir."/".$_GET['file']))
$_SESSION['message'] = "File not found!";
else
$_SESSION['message'] = $_GET['file'] . " deleted";
}
//Download a file
elseif($_GET['method'] == "download" && $_GET['file'])
{
$file = $upload_dir . "/" . $_GET['file'];
$filename = basename( $file );
$len = filesize( $file );
header( "content-type: application/stream" );
header( "content-length: " . $len );
header( "content-disposition: attachment; filename=" . $filename );
$fp=fopen( $file, "r" );
fpassthru( $fp );
}
//Rename a file
elseif( $_GET['method'] == "rename" )
{
rename( $upload_dir . "/" . $_GET['file'] , $upload_dir . "/" . $_GET['to'] );
$_SESSION['message'] = "Renamed " . $_GET['file'] . " to " . $_GET['to'];
}
//Redirect to the script again
Header("Location: " . $_SERVER['PHP_SELF']);
}
//HTML STARTING
?>
<html>
<head>
<title>FileUpload version 1.0</title>
<link href='style.css' rel='stylesheet' type='text/css'>
</head>
<body>
<table class='maintable' cellspacing=0 cellpadding=0 width=640 align='center'>
<?php
//Show logout link when logged in
if(session_is_registered('logged_in'))
{
?>
<tr>
<td class='actions'><a href='index.php?method=logout'>Logout</a></td>
</tr>
<?php
}
//Else the login screen
else
{
?>
<tr>
<td class='actions'>Please login for file upload.</td>
</tr>
<?php
}
?>
<tr>
<td class='login'>
<table class='logintable' cellspacing=2 cellpadding=2 align='center'>
<tr>
<td>
<table cellspacing=2 cellpadding=2 align='center'>
<tr>
<td>
<?php
//When logged in, show the files in the uploaded dir.
if(!session_is_registered('logged_in'))
{
?>
<form name='form' action='index.php?method=login' method='post'>
<table class='logintable' cellspacing=2 cellpadding=2 align='center'>
<td>
<table cellspacing=2 cellpadding=2 align='center'>
<tr>
<td class='login' width=40>Username:</td>
<td class='login'><input type='text' name='username'></td>
</tr>
<tr>
<td class='login'>Password:</td>
<td class='login'><input type='password' name='password'></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan=2 align='center'><input type='submit' value='login'></td>
</tr>
</table>
</form>
<?php
}
else
{
?>
<table width=350>
<tr>
<?php
//When there is a message, after an action, show it
if(session_is_registered('message'))
{
echo "<td colspan=5 class='header' align='center'><font color='red'>" . $_SESSION['message'] . "</font></td></tr><tr>";
}
?>
<td colspan=4 class='header' width=300>File</td>
<td class='header' width=70>Size</td></tr>
<?php
//Handle for the directory
$handle = opendir($upload_dir);
//Walk the directory for the files
while($entry = readdir($handle))
{
if($entry != ".." && $entry != ".")
{
//Set the filesize type (bytes, KiloBytes of MegaBytes)
$filesize = filesize($upload_dir . "/" . $entry);
$type = Array ('b', 'KB', 'MB');
for ($i = 0; $filesize > 1024; $i++)
$filesize /= 1024;
$filesize = round ($filesize, 2)." $type[$i]";
?>
<tr>
<td><A href="javascript:if(confirm('Are you sure to delete <?=$entry;?>?')) location.href='index.php?method=delete&file=<?=$entry;?>';"><img src='cross.gif' alt='Delete <?=$entry;?>' border=0></a></td>
<td><A href='index.php?method=download&file=<?=$entry;?>'><img src='dl.gif' alt='Download <?=$entry;?>' border=0></a></td>
<td><A href="javascript: var inserttext = ''; if(inserttext = prompt('Rename <?=$entry;?>. Fill in the new name for the file.','<?=$entry;?>')) location.href='index.php?method=rename&file=<?=$entry;?>&to='+inserttext; "><img src='edit.gif' alt='Rename <?=$entry;?>' border=0></a></td>
<td class='filenfo' width=300><a href='<?=$upload_dir;?>/<?=$entry;?>' target='_blank'><?=$entry;?></a></td>
<td class='filenfo' width=70><?=$filesize;?></td>
</tr>
<?php
}
}
?>
<tr>
<td class='filenfo' colspan=5><br>Upload a file.</td>
</tr>
<form method='post' enctype='multipart/form-data' action='index.php?method=upload'>
<?php
for( $i = 0; $i < $files_to_upload; $i++ )
{
?>
<tr>
<td colspan=5><input type='file' name='file[]' style='width: 100%'></td>
</tr>
<?php
}
?>
<tr>
<td colspan=5 align='center'><input type='submit' value='Upload'></td>
</tr>
</form>
</table>
<?php
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class='sign'>FileUpload version 1.1 <a href='http://www.my-php.tk'>Written by My-PHP</a></td>
</tr>
</table>
</body>
</html>
<?php
exit;
function not_allowed()
{
echo "Action not permitted. <a href='index.php'>Need to login first?</a>";
}
?>
thanks