Wikipedia PHP script/The upload script|
The script below is wrapped in "pre" tags for display. <pre> |
|
</pre> |
<?
print "<title>File upload page</title>\n";
global $id , $instr , $removeFile ;
if (isset($removeFile)) {
if (is_dir("upload/$removeFile") ) {
system ("rm -f /upload/$removeFile");
}
unset ( $removeFile ) ;
}
if (isset($Upload)) {
$Upload_name = ereg_replace(" ", "_", $Upload_name);
$abc = split("\.", $Upload_name);
$num = exec ("df");
$readata = substr($num,(strpos($num, "%")-2),2);
if ($readata > 96) {
print "<body bgcolor=white>\n";
print "<br><b>Sorry, we are almost out of disk space. We can't let you upload any";
print "files right now.</b>\n";
exit();
}
if (!is_dir("upload") ) {
system ("mkdir upload");
system ("chmod 777 upload");
}
system ("cp $Upload upload/$Upload_name");
system ("chmod 777 upload/$Upload_name");
$chec = mysql_query("select res_user from resumes where res_user='$username' and res_file_name='$Upload_name'
and res_story_pk=$id");
$nchec = mysql_num_rows($chec);
if ($nchec == 0) {
$input = mysql_query("insert into resumes (res_file_name, res_user, res_story_pk, res_update_date) values ('$Upload_name','$username', $id, current_date())");
}
print "<script language=javascript>\n";
print " function winclose(name){\n";
print " str=\"Your file was successfully uploaded!\"\n";
print " alert(str);\n";
print " }\n";
print "</script>\n";
print "<body bgcolor=white onload=\"winclose('$name')\">\n";
}
?>
<body bgcolor=white>
<div align="center"><center>
<?
####################################################################
# Instruction on #
####################################################################
global $id , $arean ;
if ($instr != "off"){
$instr = "on";
print "<table border=1 cellpadding=2>\n";
print " <tr>\n";
print " <td><strong>Instructions:</strong><ul>\n";
print " <li><strong>Use this form to upload various files</strong></li>\n";
print " <li>To replace a previously-uploaded file (e.g., a\n";
print " new version of the article), simply re-upload the\n";
print " same file. But first look below and make sure you\n";
print " haven't changed the name.</li>\n";
print " <li><strong>Here's how to upload your file. </strong>Click\n";
print " "Browse..." to your find the file you\n";
print " want to upload on your hard drive. This will open\n";
print " a "Choose file" dialogue window.</li>\n";
print " <li>When you've found the file, click "Open."\n";
print " This will select the file and close the "Choose\n";
print " file" dialogue window.</li>\n";
print " <li>Then click "Upload." The file will\n";
print " start uploading. This may take some time, if it's\n";
print " a big file and you have a slow Internet\n";
print " connection.</li>\n";
print " <li>A message will tell you when the file has\n";
print " successfully uploaded.</li>\n";
print " <li>You can upload as many files you like. Please don't\n";
print " try to crash our server, ha ha.</li>\n";
print " </ul>\n";
print " <p><font size=2 face=Garamond><a href=$PHP_SELF?id=$id&arean=$arean&instr=off>TURN INSTRUCTIONS\n";
print " OFF</a> </font></p>\n";
print " </td>\n";
print " </tr>\n";
print "</table>\n";
}
else {
$instr = "off";
print "<p><font size=2 face=Garamond>\n";
print "<a href=$PHP_SELF?id=$id&arean=$arean&instr=on>TURN INSTRUCTIONS ON</a></font></p>\n";
}
print "</center></div>\n";
print " <center>\n";
print " <form enctype=\"multipart/form-data\" action=$PHP_SELF?instr=$instr&id=$id&arean=$arean method=post>\n";
print " <input type=hidden name=max value=20096>\n";
print " <input name=Upload type=\"file\"><br>\n";
print " <input type=hidden name=update value=1>\n";
print " <input type=hidden name=step value=$step>\n";
print " <input type=submit value=UPLOAD>\n";
print "</form>\n";
print " </center>\n";
if (is_dir("upload")) {
$mydir = dir("upload");
while ($entry = $mydir->read()) {
if ($entry != "." and $entry != "..")
$file = "yes";
}
$mydir->close();
if ($file == "yes") {
print "<p align=center><b>Previously-uploaded files:</b></p>";
$mydir = opendir("upload");
$i = 0;
print "<table>\n";
while ($entry = readdir($mydir)) {
if ($entry != '.' && $entry != '..') {
print "<tr><td>" ;
print "<a href=upload/$entry>$entry</a></td><td>".filesize("upload/$entry")." bytes</td>";
print "<td><a href=\"$PHP_THIS?id=$id&instr=$instr&arean=$arean&removeFile=$entry\">Click here to remove $entry.</a></td>" ;
print "</tr>" ;
$i++;
}
}
print "</table>\n";
print "<p align=center>Click the left column to download the file.<br>Click the right column to remove the file.</p>\n";
closedir($mydir);
}
}
?>