Upload

mgd-one

Erfahrenes Mitglied
Hallo zusammen,

ich weiß das schon öffters nach einem Uload Script oder ähnlichem gefragt worden ist aber ich habe noch nichts gefunden das bei mir Funktioniert.

Meine Frage: gibt es ein File Upload Script (in PHP) das auch ohne die CHMOD rechte 777 auskommt?

Und falls das nicht geht: ich habe mir ein Upload Script runter geladen

PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>File Upload</title>
<style type="text/css">
.normal
{ 
	FONT-SIZE: 10pt; 
	COLOR: #000000;
	BACKGROUND-COLOR: Transparent;
	FONT-FAMILY: Arial, Helvetica, Sans-Serif;
	TEXT-DECORATION: None;
	FONT-WEIGHT: Bold;
}
.groß
{ 
	FONT-SIZE: 12pt; 
	COLOR: #000000;
	BACKGROUND-COLOR: Transparent;
	FONT-FAMILY: Arial, Helvetica, Sans-Serif;
	TEXT-DECORATION: None;
	FONT-WEIGHT: Bold;
}
</style>
</head>

<body>
<?PHP
$ADMIN[RequirePass] = "No";   // Checks to see if upload has a vaild password
$ADMIN[Password] = "password";   // This is the password if the above option is Yes
$ADMIN[UploadNum] = "1";  // Number of upload feilds to put on the html page
$ADMIN[directory] = "uploads";  // The directory the files will be uploaded to (must be chmoded to 777)

if ($doupload)
{
  if($ADMIN[RequirePass] == "Yes")
  {
    if($password != "$ADMIN[Password]")
	{
?>
<center>
<span class="groß">Error</span><br><br>
<table width="450" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td>
      <span class="normal">Invalid Password</span></td>
  </tr>
</table>
<br>
<input name="back" type="button" value="Back" onClick="location.href('uploader.php')">
<input name="file" type="button" value="Show directory" onClick="location.href('show.php')">
</center>
</body>
</html>
<?PHP
	  exit();
	}
  }

  $num = 0;
  while ($num < $ADMIN[UploadNum])
  {
    $num++;

    $picture = "fileup$num"."_name";
    $picture1 = $$picture;
    $picture2 = "fileup$num";
    $picture3 = $$picture2;
	
	if ($picture3 != "none")
	{
      $filesizebtyes = filesize($picture3);

      $ok = 1;
      if ($filesizebtyes < 10)
	  {
        $error .= "Error uploading (file size lower than 10 bytes) for file $num<BR>";
        $ok = 2;
      }

      if (file_exists("$ADMIN[directory]/$picture1") OR $ok == 2)
	  {
        $error .="File name already exists for file $num<BR>";
      }
	  else
	  {
        copy ($picture3, "$ADMIN[directory]/$picture1");
        $error .="File $num has been uploaded<BR>";
      }
    }
  }

  if (!$error)
  {
    $error .= "No files have been selected for upload";
  }
?>
<center>
<span class="groß">Status</span><br><br>
<table width="450" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td>
      <span class="normal"><?PHP echo $error; ?></span></td>
  </tr>
</table>
<br>
<input name="back" type="button" value="Back" onClick="location.href('uploader.php')">
<input name="file" type="button" value="Show directory" onClick="location.href('show.php')">
</center>
</body>
</html>
<?PHP
  exit();
}
else
{
  $num = 0;
  while ($num < $ADMIN[UploadNum])
  {
    $num++;
    $html .= "<tr>
                <td width=\"25%\">
                <span class=\"normal\">File $num:</span></td> 
                <td width=\"75%\">
                <input name=\"fileup$num\" type=\"file\" size=\"25\"></td>
              </tr>";
  }
?>
<form enctype="multipart/form-data" action="uploader.php" method="post">
<center>
<span class="groß">Upload</span><br><br>
<table width="450" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
	  <span class="normal">Select Files</span><br><br></td>
  </tr>
  <?PHP echo $html; ?>
</table>
<?PHP
  if ($ADMIN[RequirePass] == "Yes")
  {
?>
<table width="450" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width=\"25%\">
      <span class="normal">Password:</span></td>
	<td width=\"75%\">
      <input name="password" type="password" size="25"></td> 
  </tr>
</table>
<?PHP
  }
?>
<br>
<input name="doupload" type="submit" value="Upload Files">
<input name="file" type="button" value="Show directory" onClick="location.href('show.php')">
</center>
</form>
</body>
</html>
<?PHP
  exit();
}
?>

den verstehe ich aber nicht so richtig daher habe ich nach etwas einfacherem gesucht. Habe ich auch (unter anderem hier auf dem Board) gefunden. Nur merkwürdiger weise funktioniert nur das Script das ich nicht verstehe.

Hier noch das Script das ich verstehe aber nicht funktioniert:

PHP:
<form enctype="multipart/form-data" action="<?PHP echo $PHP_SELF ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>

<?php 
// In PHP kleiner als 4.1.0 sollten Sie $HTTP_POST_FILES anstatt $_FILES verwenden.
// In PHP kleiner als 4.0.3 verwenden Sie copy() und is_uploaded_file() anstatt von
// move_uploaded_file()

$uploaddir = '/tmp/';

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
   print "File is valid, and was successfully uploaded.  Here's some more debugging info:\n";
   print_r($_FILES);
} else {
   print "Possible file upload attack!  Here's some debugging info:\n";
   print_r($_FILES);
}
?>

hier bekomme ich immer folgende Fehler meldung:

Warning: SAFE MODE Restriction in effect. The script whose uid is 10003 is not allowed to access /tmp owned by uid 0 in [...hier steht die URl der PHP Datei...] on line 15

Ich hoffe ihr könnt mir Helfen brauche das möglichst noch vor dem WE.
 
Tja folgender Diskurs in die Userrechte von Unixbasierten Systemen:

Jeder Prozess läuft unter einem spezifischen Benutzer. Das ist für den Webserver oft z.B. wwwrun. Außerdem haben Unixbasierte Systeme eine sehr effektive Rechteverwaltung.
Das heisst, wenn der User unter dem der Webserver läuft für den Ordner, in den du die upgeloadete Datei verschieben willst, keine Schreibrechte hat, dann kann er da nunmal auch nichts hinschreiben.

Zum CHMOD. Wenn der Besitzer des Ordners der gleiche User wäre, unter dem auch der Webserver läuft, dann würde ein CHMOD von 700 reichen (Lese-, Schreib- und Ausführungsrechte für den Besitzer.

Wenn der User unter dem der Webserver läuft in der gleichen Usergruppe wie der Besitzer des Ordners ist lang 770 und wenn er nichts von alledem ist, oder z.B. unter nobody läuft, dann wirst du um xx7 nicht herumkommen.

xx, weil dann im Prinzip egal ist, was der Besitzer oder die Gruppe des Besitzers darf. Hauptsache auf Stelle 3 für Andere steht eine 7 für read,write und execute Rechte.
 
Gut das mit dem CHMOD ist ja verständlich, aber das Problem ist ich habe bei dem 2. Script dem Ordner in den die Datei verschoben werden soll auf 777 stehen (was für sicherheitsprobleme könnte ich eigentlich dadurch bekommen wenn ich CHMOD auf 777 stehen habe?) und trotzdem kommt diese Fehlermeldung. Also das Script hat die berechtigung in den Ordner zu Kopieren (schreiben).
 
Zurück