unlink oddity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, here is my problem.  Using the code below, I am saving a posted form to
a database including the files it contains.

There is one line commented out.. The unlink command.  Without the command,
the script works fine and new files

Overwrite the old files when uploaded.  If, however, I uncomment the unlink
line, the new files are still saved and the

"if (file_exists($path)) {" line evals to true, but the file disappears
after program 

Execution.  The net result of having the unlink command in seems to be that
it executes 

after program termination leaving a record of the successful upload in the
database, but

no file found on the server where the upload occurred.  Does anyone have any
idea of

why this would be occurring?  The php docs for unlink do not talk about
delayed execution

and other scripts I researched seems to use unlink before the move command
with success.

 

Any help would be greatly appreciated.

 

 

Please reply to: support@xxxxxxxxxxxxx

 

 

 

 

 

 

<?

function saveRecord ($db,$POST) {
   $bd = "/absolute_path_to_document_root";
   $fp = "/path_to_files_from_document_root/";
   $ud = $bd . $fp;

   if ($ud) mkPath($ud); // creates directory if absent
   unset($IDS);
   $names = $_FILES[obj]['name'];
   if (!empty($names) && is_array($names)) {
      while (list($objID,$name)=each($names)) {
         if (!$objID || !$name) continue;
         $IDS[] = $objID;
      }
   }
   if (!empty($IDS) && is_array($IDS)) {
      foreach ($IDS as $objID) {
         $name = $_FILES[obj]['name'][$objID]; // uploaded file name
         $type = $_FILES[obj]['type'][$objID]; // uploaded file type
         $size = $_FILES[obj]['size'][$objID]; // uploaded file size
         $fail = $_FILES[obj]['error'][$objID];// was file uploaded?
         $temp = $_FILES[obj]['tmp_name'][$objID]; // temporary file name
         $file = $objID.strrchr($name,'.'); // newly assigned file name
         $path = $ud.$file; // absolute path to newly named file
         if ($fail || !$name || !$temp) continue;
//         @unlink($ud.$file);
         @move_uploaded_file($temp, $path);
         @chmod($path, 0777);

         if (file_exists($path)) {
            $dbDAT = array(
                'name' => $name
               ,'type' => $type
               ,'size' => $size
               ,'file' => $file
               ,'path' => $fp
            );
            $OBJ[$objID] = serialize($dbDAT);                     } 
         }
      }
   }
      /*

            All the actual code to save the record in the database 

has been removed, and a fake if/then statement added.

      */

   If ($record_successfully_created) {

      Return $newRecordID;

   } else {

      Return 0;

   }        
}

 

If ($_POST[obj]) saveRecord($db,$_POST);


?>

<form method=POST action="<?=$PHP_SELF?>">

            <input type=hidden name="form[id]" value="23">

            <input type=text name="obj[1234]" value="value 1">

            <input type=text name="obj[1235]" value="value 2">

            <input type=file   name="obj[1236]">

            <input type=file   name="obj[1237]">

</form>


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux