[Home]Wikipedia PHP script/The upload script

HomePage | Wikipedia PHP script | Recent Changes | Preferences

Showing revision 1
<?
	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 "
Sorry, we are almost out of disk space. We can't let you upload any"; print "files right now.\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>

<?

    ####################################################################
    # Instruction on                                                   #
    ####################################################################
    global $id , $arean ;
    if ($instr != "off"){
	$instr = "on";
	print "\n";
	print "    \n";
	print "        \n";
	print "    \n";
	print "
Instructions:
    \n"; print "
  • Use this form to upload various files
  • \n"; print "
  • 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.
  • \n"; print "
  • Here's how to upload your file. 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.
  • \n"; print "
  • When you've found the file, click "Open."\n"; print " This will select the file and close the "Choose\n"; print " file" dialogue window.
  • \n"; print "
  • 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.
  • \n"; print "
  • A message will tell you when the file has\n"; print " successfully uploaded.
  • \n"; print "
  • You can upload as many files you like. Please don't\n"; print " try to crash our server, ha ha.
  • \n"; print "
\n"; print "

<a href=$PHP_SELF?id=$id&arean=$arean&instr=off>TURN INSTRUCTIONS\n"; print " OFF</a>

\n"; print "
\n"; } else { $instr = "off"; print "

\n"; print "<a href=$PHP_SELF?id=$id&arean=$arean&instr=on>TURN INSTRUCTIONS ON</a>

\n"; } print "
\n";

  print " 
\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\">
\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 "
\n";

	if (is_dir("upload")) {
		$mydir = dir("upload");
			while ($entry = $mydir->read()) {
			if ($entry != "." and $entry != "..")
				$file = "yes";
			}
		$mydir->close();

		if ($file == "yes") {
			print "

Previously-uploaded files:

"; $mydir = opendir("upload"); $i = 0; print "\n"; while ($entry = readdir($mydir)) { if ($entry != '.' && $entry != '..') { print ""; print "" ; print "" ; $i++; } } print "
" ; print "<a href=upload/$entry>$entry</a>".filesize("upload/$entry")." bytes<a href=\"$PHP_THIS?id=$id&instr=$instr&arean=$arean&removeFile=$entry\">Click here to remove $entry.</a>
\n"; print "

Click the left column to download the file.
Click the right column to remove the file.

\n"; closedir($mydir); } }

?>


HomePage | Wikipedia PHP script | Recent Changes | Preferences
This page is read-only | View other revisions | View current revision
Edited August 26, 2001 3:06 am by Magnus Manske (diff)
Search: