Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#1

[PHP] touch geht nicht

  Alt 16. Nov 2005, 05:18
Ich versuche gerade mit touch das Datum einer Datei neu zu setzen. Doch
leider schlägt touch mit der Fehlermeldung
Zitat:
Warning: touch(): Utime failed: Operation not permitted in
/var/www/l3s11195/html/Developer/Artikel/settimestamp.php on line 48
fehl.

Die entsprechende Zeile sieht wie folgt aus:
Code:
touch("ICQLog_Win32API.shtml", strtotime("2003-09-17 15:12"));
Ist der Server eventuell so konfiguriert, dass diese Operation nicht erlaubt
ist?

Eine Datei mit touch anlegen geht übrigens.

Jetzt habe ich auf http://de.php.net gelesen:
Zitat:
Here's a little workaround that allows the PHP user to touch a file it
doesn't own:

Code:
<?php

   $target_file = "/path/to/file/filename.txt"; //system filepath to your
file
   $file_content = implode("",file($target_file));
   @unlink($target_file);
   if($savetofile = fopen($target_file, "w")) {
       fputs($savetofile, $file_content);
       fclose($savetofile);
   }
   $new_date = strtotime("23 April 2005"); // set the required date
timestamp here
   touch($target_file,$new_date);

?>
Bzw. die Ergänzung:
Zitat:
Here's how the code SHOULD be written:

Create the new file FIRST, rather than last, with a different
name such as $file.tmp.
Read the ownership, permissions, and creation time of the old file.
Set permissions and creation time of the new file the same as the old.
Rename the new file to the name of the old.
chown() the new file to the user that owned the file it's replacing.
Daraus resultiert folgend er Code:

Code:
function mytouch($file, $timestamp)
   {
     clearstatcache();
     $file = $_SERVER['DOCUMENT_ROOT']."/Developer/Artikel/".$file;
     echo "Datei: $file
";
     $ctime = filectime($file);
     echo "Datum: ".date("Y-m-d H:i", $ctime)."
";
     $owner = posix_getpwuid((fileowner($file)));
     echo "Besitzer: ".$owner["name"]."
";
     $perm = decoct(fileperms($file));
     echo "Attribute: $perm
";
     $file_content = implode("",file($file));
     if($savetofile = fopen('~.tmp', "w")) {
         fputs($savetofile, $file_content);
         fclose($savetofile);
     }

     if (@chmod('~.tmp', octdec($perm)))
     {
       echo "Attribute neu: ".decoct(fileperms('~.tmp'))."
";
     }
     else
     {
       echo "Dateiattribute konnten nicht gesetzt werden.
";
     }

     touch('~.tmp', $ctime);

     rename('~.tmp', $file);

     if (@chown($file, intval($owner["uid"])))
     {
       $owner = posix_getpwuid((fileowner($file)));
       echo "Besitzer: ".$owner["name"]."
";
     }
     else
     {
       echo "Besitzer konnte nicht geändert werden.
";
       $owner = posix_getpwuid((fileowner($file)));
       echo "Besitzer neu: ".$owner["name"]."
";
     }

     $new_date = $timestamp; // set the required date timestamp here
     $err = touch($file,$new_date);
     if ($err)
     {
       echo "Datum neu: ".date("Y-m-d H:i", filemtime($file))."
";
     }
     echo "<hr>
";
     return $err;
   }
Aber da nach ist der Besitzer immer "apache". Was natürlich nicht erwünscht
ist.

Nach dem mir die Datei nicht mehr gehört, sondern "apache" der Besitzer ist,
schlägt folgende Zeile
Code:
include $_SERVER['DOCUMENT_ROOT'].'/includes/head.shtml';
Mit folgenden Warnungen fehl:
Zitat:
Warning: main(): SAFE MODE Restriction in effect. The script whose uid is 48
is not allowed to access /var/www/l3s11195/html/includes/head.shtml owned by
uid 3922 in /var/www/l3s11195/html/Developer/Artikel/API_Zauberwuerfel.php
on line 13

Warning: main(/var/www/l3s11195/html/includes/head.shtml): failed to open
stream: No such file or directory in
/var/www/l3s11195/html/Developer/Artikel/API_Zauberwuerfel.php on line 13

Warning: main(): Failed opening '/var/www/l3s11195/html/includes/head.shtml'
for inclusion (include_path='.') in
/var/www/l3s11195/html/Developer/Artikel/API_Zauberwuerfel.php on line 13
Und deswegen müsste entweder touch funktionieren oder ich muss mit dem
Script (mytouch) Besitzer der Datei bleiben.

Ich bin da etwas ratlos, was da auf dem Server los ist. Es muss doch möglich
sein das Dateidatum von Dateien zu ändern deren Besitzer ich bin.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat