Location: PHPKode > projects > OpenBizMap > openbizmap/mydata/script/script_upload.html
<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

$field=get('field');

echo '<div>';

if($_FILES['odb_file']['size']>0)
{
  $ext=strtolower(substr($_FILES['odb_file']['name'],strrpos($_FILES['odb_file']['name'],'.')));
  $name=purename(substr($_FILES['odb_file']['name'],0,strrpos($_FILES['odb_file']['name'],'.')));
  $preamble=substr(purename($name),0,1).'/'.substr(purename($name),0,2);
  addpath(cfg_data_path.'/data/files/'.$preamble);

  $tmpcnt=0;
  $filename=$name.$ext;
  while(file_exists(cfg_data_path.'/data/files/'.$preamble.'/'.$filename.'.file'))
  {
    $tmpcnt++;
    $filename=$name.'_'.$tmpcnt.$ext;
  }

  if(move_uploaded_file($_FILES['odb_file']['tmp_name'], cfg_data_path.'/data/files/'.$preamble.'/'.$filename.'.file'))
  {
    echo '<h2>';
    myecho('File was successfully uploaded.');
    echo '</h2>';


    $variable_name=substr(str_replace('_',' ',substr($field,0,strrpos($field,'_'))),4);
    $sysId=substr($field,strrpos($field,'_')+1);

    if(0+$sysId==0)
    {
      $variable_name=substr(str_replace('_',' ',$field),4);
      $session_array['FileUpload'.$variable_name]=$filename.'.file';
    }
    else
    {
      $line_array=search('sysId='.$sysId.'');

      if($variable_name)
      {
        $variable_array=line2array($line_array[0]);

        reset($variable_array);
        foreach($variable_array as $tmp_variable_name => $tmp)
        {
          if(purename($tmp_variable_name)==$variable_name)
          {
            $variable_name=$tmp_variable_name;
            break;
          }
        }

        $old_variable_array=$variable_array;
        $variable_array[$variable_name]=$filename.'.file';

        //USEREXIT OnSave
        $userexit='onsave';
        if(file_exists(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt'))
        {
          include(cfg_data_path.'/config/userexit/exit_'.$userexit.'.txt');
        }
        else
        {
          include(cfg_data_path.'/script/userexit/exit_'.$userexit.'.txt');
        }

        save($variable_array);
      }
    }
  }
  else
  {
    echo '<h2>';
    myecho('File cannot be uploaded.');
    echo '</h2>';
  }
}
else
{
  echo '<h2>';
  myecho('Upload file');
  echo '</h2>';

  echo '<form enctype="multipart/form-data" action="odb_index.php" method="POST">';
    echo('<input name="odb_script" type="hidden" value="upload"></input>');
    echo('<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />');
    echo('<input type="hidden" name="odb_field" value="'.$field.'" />');
    echo('<input type="hidden" name="odb_search" value="---" />');
    echo('<input type="hidden" name="odb_popup" value="1" />');
    echo '<input name="odb_file" type="file"></input>';
    echo('<input name="odb_import" type="submit" value="Upload"></input>');
  echo '</form>';
}
echo '</div>';
?>
Return current item: OpenBizMap