Data Management using PHP and shell scripts

From EGEE-see WIki

Jump to: navigation, search

PHP form fo uploading a file to the Grid, which means transfering it from local machine to SE and registering it in file catalog:


upload.html



Image:image1.jpg

<form action="uploader.php" method="GET">
<table>
   <tr>
       <td>Source file location: </td>
       <td>
           <input name="uploadedfile" type="file" />
       </td>
   </tr>
   <tr>
       <td>Destination SE:</td>
       <td><input name="destse" type="text" /></td>
   </tr>
   <tr>
       <td>Destination directory: </td>
       <td><input name="destdirectory" type="text" /></td>
   </tr>
   <tr>
       <td>Destination file name: </td>
       <td><input name="destfilename" type="text" /></td>
   </tr>
   <tr>
       <td><input type="submit" value="Upload File" /></td>
   </tr>
</table>
</form>


Uploader.php

<?php

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

       echo "The file ".  basename( $_FILES['uploadedfile']['name']) . " has been uploaded";
       
       echo $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
 
       $destdirectory = $_GET['=destdirectory'];

       $destfilename = $_GET['destfilename'];

       $destse = $_GET['destse'];

       $cmd = "lcg -cr -v --vo -d" . $destse . "-l lfn:/" . $destdirectory . "/" 
       . $destfilename . " " . basename( $_FILES['uploadedfile']['name']) 

       echo exec($cmd);

}
else
{
      
       echo "There was an error uploading the file, please try again!";
}

?>
Personal tools