All pastes #609110 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-08 17:58 UTC
rendered paste body
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Image Uploader</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function highlight(field) {
	field.focus();
  	field.select();
}
// End -->
</SCRIPT>
</head>
<body>

Upload images: ( Do not upload any pornographic images, if someone does this will not be public )
<FORM ENCTYPE="multipart/form-data" ACTION="<?php echo $PHP_SELF; ?>" METHOD="POST">
The file: <INPUT TYPE="file" NAME="userfile"><INPUT TYPE="submit" VALUE="Upload">
</FORM>
<?php

// this is the absolute path to where you want the files uploaded
// the default is a folder called 'img' in the html root folder 
// (usually public_html): BE SURE TO SET WRITE ACCESS (chmod 777)
$folder = 'public';
$path = $_SERVER['DOCUMENT_ROOT'].'/'.$folder.'/';

// don't know your absolute path?  
// uncomment the following line to have it print the
// absolute path of this script to the page
// echo $_SERVER['SCRIPT_FILENAME'];

// this is the max allowed file size in bytes
$max_size = 5242880;

if (!isset($HTTP_POST_FILES['userfile'])) exit;

if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

   if ($HTTP_POST_FILES['userfile']['size']>$max_size) { 
      echo "The file is too big<br>\n"; 
	  exit; 
   }

   if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || 
       ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || 
	   ($HTTP_POST_FILES['userfile']['type']=="image/jpg") || 
	   ($HTTP_POST_FILES['userfile']['type']=="image/png")) {

	  // append random seed
	  $pos = strrpos($HTTP_POST_FILES['userfile']['name'],'.');
	  $nme = substr($HTTP_POST_FILES['userfile']['name'],0,$pos);
	  $ext = substr($HTTP_POST_FILES['userfile']['name'],$pos);
	  $sed = dechex(rand(256,4095));
	  $HTTP_POST_FILES['userfile']['name'] = $nme.$sed.$ext;
	  
	  // if file still already exists, try a different seed
      while (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { 
		 $sed = dechex(rand(256,4095));
		 $HTTP_POST_FILES['userfile']['name'] = $nme.$sed.$ext;
      }

      $res = @copy($HTTP_POST_FILES['userfile']['tmp_name'], $path.$HTTP_POST_FILES['userfile']['name']);

      if (!$res) { 
         echo "Upload failed! Check the upload folder's permissions.<br>\n"; exit; 
      } else { 
      echo "Upload sucessful!<br>\n"; 
      }

      echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
      echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
      echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
	  
	  $link_s = 'http://'.$_SERVER['HTTP_HOST'].'/'.$folder.'/'.$HTTP_POST_FILES['userfile']['name'];
	  $link_i = "[img]".$link_s."[/img]";
	  echo "<img src=\"$link_s\"><br>\n";
	  echo "URL: <input onClick='highlight(this);' class=\"textinput\" type=\"text\" value=\"$link_s\" size=\"70\"><br>\n";
	  echo "BBCode: <input onClick='highlight(this);' class=\"textinput\" type=\"text\" value=\"$link_i\" size=\"70\"><br>\n";

   } else { 
      echo "Wrong file type!<br>\n"; 
      exit; 
   }

}

?> 
</body>
</html>