Example #1
0
 /**
  * Deletes a file.
  *
  * Called when this component receives an HTTP DELETE request to
  * /zip/$a/$b/$c/$file.
  *
  * @param string $hash The hash of the file which should be deleted.
  */
 public function deleteZip($callName, $input, $params = array())
 {
     $path = array(self::getBaseDir(), $params['a'], $params['b'], $params['c'], $params['file']);
     $filePath = implode('/', array_slice($path, 0));
     if (strlen($filePath) > 0 && file_exists($this->config['DIR']['files'] . '/' . $filePath)) {
         // after the successful deletion, we want to return the file data
         $file = new File();
         $file->setAddress($filePath);
         $file->setFileSize(filesize($this->config['DIR']['files'] . '/' . $filePath));
         $file->setHash(sha1_file($this->config['DIR']['files'] . '/' . $filePath));
         $file->setMimeType("application/zip");
         // removes the file
         unlink($this->config['DIR']['files'] . '/' . $filePath);
         // the removing/unlink process failed, if the file still exists.
         if (file_exists($this->config['DIR']['files'] . '/' . $filePath)) {
             return Model::isProblem(new File());
         }
         // the file is removed
         return Model::isCreated($file);
     } else {
         // file does not exist
         return Model::isProblem(new File());
     }
 }
Example #2
0
// variable r (0=just updates, 1=all, 2=all and don't update gui_notify)
$json = file_get_contents('http://localhost:8081/file_list.json?r=0&e=1');
$data = json_decode($json, false);
if (get_debug()) {
    var_dump($data);
}
// loop through messages
foreach ($data->files as $item) {
    // check if has been successfully downloaded
    if ($item->status >= 4) {
        // check if file already exists
        $file = FileQuery::create()->filterByHash($item->hash)->findOne();
        if (!$file) {
            // put file information into data base
            $file = new File();
            $file->setHash($item->hash);
            $file->setSuffix($item->suffix);
            $file->setDescription($item->description);
            $file->setSize($item->size);
            $file->setTime($item->time);
            $file->setStatus($item->status);
            $file->save();
            // advertise this file via twitter
            // TODO: send images < 3MB directly to twitter
            $txt = $file->getDescription() . " " . twitter_file_link($file);
            twitter_send2twitter($txt);
            if (get_debug()) {
                echo "advertised file on twitter: {$txt}\n";
            }
        }
    } else {