Erweiterung Uploadscript Hilfe gesucht

Limitter

Grünschnabel
Hallo Leute,

ich habe ein Problem und zwar möchte ich gerne ein Uploadscript erweitern.
Das angeführte Script soll wie folgt erweitert werden:

- ein Thumbnail soll erstellt werden mittels GD
- die Ausgabe des Uploads soll als HTML oder BB Code erfolgen

Optimalerweise erfolgt die Ausgabe des Codes in einem Formularfeld.

Vielen Dank für Eure Hilfe schonmal im voraus

Limitter



Ausgabe als HTML Code
Code:
<a href="http://BildUrl.de"><img src="http://Thumnail_Pfad.de" border="0"></a>

Ausgabe als BB Code
Code:
[ URL=http://BildUrl.de][ IMG]http://Thumnail_Pfad.de[ /IMG][ /URL]


http_upload.php
Code:
<?


include ('global.php');
include ('http_upload_config.php');

if (empty($_REQUEST['do']))
{
	$_REQUEST['do'] = 'login';
}

if ($_REQUEST['do'] == 'login')
{

if ( $DBauthentification == '1' )
{
?>
<html>
<head>
<title>Login for Files to Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<!-- no cache headers -->
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="-1" />
	<meta http-equiv="Cache-Control" content="no-cache" />
	<!-- end no cache headers -->
</head>

<body>
<form name="form1" method="post" action="http_upload.php">
  <p>Enter your login name:
    <input name="login" type="text" id="login" maxlength="10"></p>
  <p>
  <p>Enter your password:&nbsp;
    <input name="password" type="password" id="password" maxlength="10"></p>
  <p>
    <input type="submit" name="Submit" value="Submit">
    <input type="hidden" name="do" value="verify">
  </p>
</form>
</body>
</html>
<?
}
else
{
    //echo "VBulletin Access";
    $_REQUEST['do'] = 'verify';
}
}

if ($_REQUEST['do'] == 'verify')
{
?>
<html>
<head>
<title>Login for Files to Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<!-- no cache headers -->
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="-1" />
	<meta http-equiv="Cache-Control" content="no-cache" />
	<!-- end no cache headers -->
</head>

<body>
<?

$_SESSION["accessing"] = "7";

  if ( $DBauthentification == '0' )
  {
            echo "Checking authentification ...<BR><BR>";
            
            if(in_array($bbuserinfo[usergroupid], $AUTH_NOACCESS))
            {
            echo "No Access because Usergroup is wrong";
            }
            else
            {
                 if(in_array($bbuserinfo[usergroupid], $AUTH_ACCESS))
                 {
                     echo "Access granted.<BR>";
                     echo "<form name=\"formnew\" method=\"post\" action=\"http_upload.php\">";
                     echo "<input type=\"hidden\" name=\"accessing\" value=\"1\">";
                     echo "<input type=\"submit\" name=\"Submit\" value=\"Continue...\">";
                     echo "<input type=\"hidden\" name=\"do\" value=\"boxes\">";
                     echo "</Form>";
                     //$accessing = "1";
                     //session_register('accessing');
                     echo "\n</Body>\n</HTML>";
                 }
                 else
                 {
                     echo "No Access because Usergroup is unknown";
                 }
                 //endif
            }
            //endif
            
  }
  else
  {

    if ( $_POST['login'] == '' || $_POST['password' == '' ])
    {
        echo "NO WAY<BR><BR>";
        echo "<A HREF=\"http_upload.php?do=login\">Back</A>";
        echo "</Body>";
        echo "</HTML>";
    }
    else
    {
        $_SESSION["accessing"] = "7";
        $check1 = strcmp ($_POST['login'],$login);
        if ( $check1 == '0' )
        {
            $check2 = strcmp ($_POST['password'],$password);
            if ( $check2 == '0' )
            {
               echo "OK<BR><BR>";
                     echo "<form name=\"formnew\" method=\"post\" action=\"http_upload.php\">";
                     echo "<input type=\"hidden\" name=\"accessing\" value=\"1\">";
                     echo "<input type=\"submit\" name=\"Submit\" value=\"Continue...\">";
                     echo "<input type=\"hidden\" name=\"do\" value=\"boxes\">";
                     echo "</Form>";
            }
            else
            {
               echo "NO WAY<BR><BR>";
               echo "<A HREF=\"http_upload.php?do=login\">Back</A>";
            }
        }
        else
        {
               echo "NO WAY<BR><BR>";
               echo "<A HREF=\"http_upload.php?do=login\">Back</A>";
        }
        
    }
  }
}


if ($_REQUEST['do'] == 'boxes')
{
    if ( $_POST["accessing"] == "1" )
    {
?>
<html>
<head>
<title># of Files to Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<!-- no cache headers -->
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="-1" />
	<meta http-equiv="Cache-Control" content="no-cache" />
	<!-- end no cache headers -->
</head>

<body>
<form name="form1" method="post" action="http_upload.php">
  <p>Enter the amount of files you want to upload. Max = 9.</p>
  <p>
    <input name="uploadNeed" type="text" id="uploadNeed" maxlength="1">
  </p>
  <p>
    <input type="submit" name="Submit" value="Submit">
    <input type="hidden" name="do" value="upload">
    <input type="hidden" name="accessing" value="1">
  </p>
</form>
</body>
</html>
<?
}
else
{
               echo "NO WAY<BR><BR>";
               echo "<A HREF=\"http_upload.php?do=login\">Back</A>";
}
//endif
}

if ($_REQUEST['do'] == 'upload')
{
    if ( $_POST["accessing"] == "1" )
    {
?>
<html>
<head>
<title># of Files to Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<!-- no cache headers -->
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="-1" />
	<meta http-equiv="Cache-Control" content="no-cache" />
	<!-- end no cache headers -->
</head>

<body>
<?

if ( $_POST['uploadNeed'] == 0 )
{
    echo "Please specify how many files you want to upload. Go Back.<BR><BR>";
                     echo "<form name=\"formnew\" method=\"post\" action=\"http_upload.php\">";
                     echo "<input type=\"hidden\" name=\"accessing\" value=\"1\">";
                     echo "<input type=\"submit\" name=\"Submit\" value=\"Back\">";
                     echo "<input type=\"hidden\" name=\"do\" value=\"boxes\">";
}
else
{
?>

<form name="form1" enctype="multipart/form-data" method="post" action="http_upload.php">
  <p>
  Please specify for each field which file you want to upload:<BR><BR>
  <?
  // start of dynamic form
  $uploadNeed = $_POST['uploadNeed'];
  for($x=0;$x<$uploadNeed;$x++){
  ?>
    <input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>">
  </p>
  <?
  // end of for loop
  }
  ?>
  <p><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
    <input type="submit" name="Submit" value="Submit">
    <input type="hidden" name="do" value="process">
    <input type="hidden" name="accessing" value="1">
  </p>
</form>
<?
        echo "Supported file types are:<BR><BR><B>";
        foreach($file_type as $extension)
        {
            echo $extension,"&nbsp;&nbsp;&nbsp;&nbsp;";
        }
?>
</body>
</html>
<?
}
}
else
{
               echo "NO WAY<BR><BR>";
               echo "<A HREF=\"http_upload.php?do=login\">Back</A>";
}
//endif
}

if ($_REQUEST['do'] == 'process')
{
   if ( $_POST["accessing"] == "1" )
   {
      $uploadNeed = $_POST['uploadNeed'];
      // start for loop
      for($x=0;$x<$uploadNeed;$x++)
      {
        $file_name = $_FILES['uploadFile'. $x]['name'];
        $ext_array =explode(".",$file_name);
        $last_position = count($ext_array) - 1;
        $extension = $ext_array[$last_position];

        if(in_array($extension, $file_type))
        {
        // strip file_name of slashes
        $file_name = stripslashes($file_name);
        $file_name = str_replace("'","",$file_name);

        if ( $overwrite == "1" )
        {
            if ( file_exists ($file_name))
            {
                $status_file = "OVERWRITTEN";
            }
            else
            {
                $status_file = "uploaded";
            }
            $copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
            // check if successfully copied
            if($copy)
            {
                    echo "<B>$file_name</B> has been ".$status_file." sucessfully!<br>";
            }
            else
            {
            echo "<B>$file_name</B> could not be uploaded!<br>";
            }
        }
        else
        {

        if ( file_exists ($file_name))
        {
        echo "File <B>$file_name</B> exists<BR>";
        
        }
        else
        {
        $copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
        // check if successfully copied
        if($copy)
        {
        echo "<B>$file_name</B> has been uploaded sucessfully!<br>";
        }
        else
        {
        echo "<B>$file_name</B> could not be uploaded!<br>";
        }
        }
        }
        }
        else
        {
        echo "This file type <B>",$extension,"</B> is not supported !<BR><BR>";
        echo "Supported file types are:<BR><BR><B>";
        foreach($file_type as $extension)
        {
            echo $extension,"&nbsp;&nbsp;&nbsp;&nbsp;";
        }
        }

      } // end of loop

        echo "<BR><BR><A HREF=\"http_upload.php?do=login\">Back</A>";
}
else
{
               echo "NO WAY<BR><BR>";
               echo "<A HREF=\"http_upload.php?do=login\">Back</A>";
}
//endif
}
?>


http_upload_config.php
Code:
<?

// ######################## Define Back-End Authentification ##################

// Auth = 0 -> Authentification against VBulletin Database
// Auth = 1 -> Authentification against Password section from below
$DBauthentification = '0';

// ######################## Define file types for upload ######################

// Please define which file types you want to allow for upload
$file_type = array("gif","png","jpg","jpeg","zip","tar","swf");

// ############# Overwrite setting for existing files #########################

// THIS IS DANGEROUS ! If you set this to 1 every file will be overwritten
// without any further questions or comments. The file can not be recovered

$overwrite = '0';

// ######################## Define VB database usergroup authentification #####

// only works if Authentification is set to 1

# You want to exclude a usergroup from access to http upload.
# Please specify VBulletin UsergroupID from ACP
$AUTH_NOACCESS  = array(2,3,5,8);

# Please specify which VBulletin UsergroupIDs should have access to http upload
$AUTH_ACCESS    = array(6);

// ######################## Password section for http upload ##################

// only works if Authentification is set to 0

$login = "Admin";
$password = "noway";

?>
 
Original geschrieben von Limitter
Hallo Leute,

ich habe ein Problem und zwar möchte ich gerne ein Uploadscript erweitern.
Das angeführte Script soll wie folgt erweitert werden:

- ein Thumbnail soll erstellt werden mittels GD
- die Ausgabe des Uploads soll als HTML oder BB Code erfolgen


Also ich kann dir mal mit dem Thumbnail Script aushelfen:

Code:
move_uploaded_file($tempname,"PFAD");
    $bild="PFAD";
    //Bildinformationen auslesen
    $size=getimagesize($bild);
    $breite=$size[0];
    $hoehe=$size[1];
    //hier die Breite festlegen
    $neueHoehe=80;
    $neueBreite=intval($breite*$neueHoehe/$hoehe);
    //Thumbnail erstellen und speichern
    $altesBild=ImageCreateFromJPEG($bild);
    $neuesBild=ImageCreateTrueColor($neueBreite,$neueHoehe);
    ImageCopyResized($neuesBild,$altesBild,0,0,0,0,$neueBreite,$neueHoehe,$breite,$hoehe);
    ImageJPEG($neuesBild, "NEUER PFAD");
    unlink($bild);

$bild ist da wo du die Datei hin uploadest, ich hab Temp.jpg.

Ich hoff ich konnte dir helfen.....

Grüsse,

Choco
 

Neue Beiträge

Zurück