Ejemplo n.º 1
0
 public function avatar_post($id)
 {
     $tempImage = tempnam_sfx(sys_get_temp_dir(), "jpg");
     $imageName = base64_to_png($this->post('image'), $tempImage);
     $thumbImage = create_thumb($imageName);
     $nameThumb = name_thumb($imageName);
     $handle = fopen($imageName, "r");
     $data = fread($handle, filesize($imageName));
     $headers = array('Authorization: Client-ID ' . IMGUR_CLIENT_ID);
     $postFields = array('image' => base64_encode($data));
     $dataImage = send_post(IMGUR_URL_UPLOAD_IMAGE, $postFields, $headers);
     $handle = fopen($nameThumb, "r");
     $data = fread($handle, filesize($nameThumb));
     $headers = array('Authorization: Client-ID ' . IMGUR_CLIENT_ID);
     $postFields = array('image' => base64_encode($data));
     $dataThumb = send_post(IMGUR_URL_UPLOAD_IMAGE, $postFields, $headers);
     $val['avatar_thumbnail'] = $dataThumb['data']['link'];
     $val['avatar_standar'] = $dataImage['data']['link'];
     $userId = $this->user_model->update($id, $val);
     if (!is_null($userId)) {
         //unlink($imageName);
         //unlink($nameThumb);
         $this->response(array('avatars' => $val), 200);
     } else {
         $this->response(array('error' => 'Internal Server Error'), 500);
     }
 }
Ejemplo n.º 2
0
function put_file_x1($path, $byte)
{
    $byte = str_replace(' ', '', $byte);
    //处理数据
    $byte = str_ireplace("<", '', $byte);
    $byte = str_ireplace(">", '', $byte);
    $byte = file_get_contents($byte);
    $file = tempnam_sfx($path, ".mp4");
    $handle = fopen($file, "w");
    fwrite($handle, $byte);
    fclose($handle);
    return $file;
}
Ejemplo n.º 3
0
 public function restoreConfig()
 {
     // phase 1 retrieve data from browser
     // extraemos los datos de registro
     $data = http_request("Data", "s", null);
     if (!$data) {
         return array("errorMsg" => "restoreConfig()::download(): No data to import has been received");
     }
     if (!preg_match('/data:([^;]*);base64,(.*)/', $data, $matches)) {
         return array("errorMsg" => "restoreConfig()::download() cannot handle data received from browser");
     }
     // mimetype for excel file is be stored at $matches[1]: and should be checked
     // $type=$matches[1]; // 'text/plain', or whatever. Not really used
     $contents = base64_decode($matches[2]);
     // decodes received data
     // phase 2 store it into temporary file
     $tmpfile = tempnam_sfx(__DIR__ . "/../../../logs", "import", "xlsx");
     $file = fopen($tmpfile, "wb");
     fwrite($file, $contents);
     fclose($file);
     $res = parse_ini_file($tmpfile, false);
     // don't parse subsections
     if (!$res) {
         return array("errorMsg" => "restoreConfig()::download() Received data is not a '.ini' file");
     }
     // phase 3 analyze data. skip internal vars, ignore unknown ones
     $result = array();
     // create result string arrray to send to browser
     $data = array();
     // create array to store valid entries
     foreach ($res as $key => $value) {
         $key = strtolower($key);
         // si no existe se ignora
         if (!array_key_exists($key, Config::$config_options)) {
             array_push($result, "{$key}: Unknown. Ignored");
             continue;
         }
         // si es de sistema se ignora
         if (Config::$config_options[$key][1] == true) {
             array_push($result, "{$key}: Forbidden. Ignored");
             continue;
         }
         // check format
         $type = "";
         switch (Config::$config_options[$key][0]) {
             case 's':
                 if (is_string($value)) {
                     $type = "string";
                 }
                 break;
             case 'c':
                 if (is_color($value)) {
                     $type = "color";
                 }
                 break;
             case 'f':
                 // trick to detect if an string contains a float
                 $floatVal = floatval($value);
                 if ($floatVal && intval($floatVal) != $floatVal) {
                     $type = "float";
                 }
                 break;
             case 'i':
                 if (is_numeric($value) && strpos($value, '.') == false) {
                     $type = "int";
                 }
                 break;
             case 'b':
                 if ($value == "1" || $value == "0") {
                     $type = "bool";
                 }
                 break;
         }
         if ($type == "") {
             array_push($result, "{$key}: Invalid format. Ignored");
             continue;
         }
         // arriving here means data is valid
         // array_push($result,"$key: ($type) $value Accepted");
         $data[$key] = $value;
     }
     // finally write file:
     $res = array_merge($this->config, $data);
     $wres = $this->write_ini_file($res, AC_CONFIG_FILE);
     if ($wres === FALSE) {
         return array("errorMsg" => "restoreConfig()::save() error saving .ini file");
     }
     return array('data' => join('<br />', $result));
 }
Ejemplo n.º 4
0
 public function retrieveExcelFile()
 {
     // phase 1 retrieve data from browser
     $this->myLogger->enter();
     $this->saveStatus("Loading file...");
     // extraemos los datos de registro
     $data = http_request("Data", "s", null);
     if (!$data) {
         return array("errorMsg" => "importExcel(dogs)::download(): No data to import has been received");
     }
     if (!preg_match('/data:([^;]*);base64,(.*)/', $data, $matches)) {
         return array("operation" => "upload", "errorMsg" => "importExcel(dogs)::download() Invalid received data format");
     }
     // mimetype for excel file is be stored at $matches[1]: and should be checked
     // $type=$matches[1]; // 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', or whatever. Not really used
     $this->myLogger->leave();
     $contents = base64_decode($matches[2]);
     // decodes received data
     // phase 2 store it into temporary file
     $tmpfile = tempnam_sfx(__DIR__ . "/../../../logs", "import", "xlsx");
     $file = fopen($tmpfile, "wb");
     fwrite($file, $contents);
     fclose($file);
     return array("operation" => "upload", "success" => true, "filename" => $tmpfile);
 }