function ws_images_addFlickr($photo, &$service) { if (!is_admin()) { return new PwgError(403, 'Forbidden'); } global $conf; if (empty($conf['flickr2piwigo']['api_key']) or empty($conf['flickr2piwigo']['secret_key'])) { return new PwgError(null, l10n('Please fill your API keys on the configuration tab')); } include_once PHPWG_ROOT_PATH . 'admin/include/functions.php'; include_once PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'; include_once FLICKR_PATH . 'include/functions.inc.php'; if (test_remote_download() === false) { return new PwgError(null, l10n('No download method available')); } // init flickr API include_once FLICKR_PATH . 'include/phpFlickr/phpFlickr.php'; $flickr = new phpFlickr($conf['flickr2piwigo']['api_key'], $conf['flickr2piwigo']['secret_key']); $flickr->enableCache('fs', FLICKR_FS_CACHE); // user $u = $flickr->test_login(); if ($u === false or empty($_SESSION['phpFlickr_auth_token'])) { return new PwgError(403, l10n('API not authenticated')); } // photos infos $photo_f = $flickr->photos_getInfo($photo['id']); $photo = array_merge($photo, $photo_f['photo']); $photo['url'] = $flickr->get_biggest_size($photo['id'], 'original'); $photo['path'] = FLICKR_FS_CACHE . 'flickr-' . $u['username'] . '-' . $photo['id'] . '.' . get_extension($photo['url']); // copy file if (download_remote_file($photo['url'], $photo['path']) == false) { return new PwgError(null, l10n('Can\'t download file')); } // category if (!preg_match('#^[0-9]+$#', $photo['category'])) { $categories_names = explode(',', $photo['category']); $photo['category'] = array(); foreach ($categories_names as $category_name) { $query = ' SELECT id FROM ' . CATEGORIES_TABLE . ' WHERE LOWER(name) = "' . strtolower($category_name) . '" ;'; $result = pwg_query($query); if (pwg_db_num_rows($result)) { list($cat_id) = pwg_db_fetch_row($result); $photo['category'][] = $cat_id; } else { $cat = create_virtual_category($category_name); $photo['category'][] = $cat['id']; } } } else { $photo['category'] = array($photo['category']); } // add photo $photo['image_id'] = add_uploaded_file($photo['path'], basename($photo['path']), $photo['category']); // do some updates if (!empty($photo['fills'])) { $photo['fills'] = rtrim($photo['fills'], ','); $photo['fills'] = explode(',', $photo['fills']); $updates = array(); if (in_array('fill_name', $photo['fills'])) { $updates['name'] = pwg_db_real_escape_string($photo['title']); } if (in_array('fill_posted', $photo['fills'])) { $updates['date_available'] = date('Y-m-d H:i:s', $photo['dates']['posted']); } if (in_array('fill_taken', $photo['fills'])) { $updates['date_creation'] = $photo['dates']['taken']; } if (in_array('fill_author', $photo['fills'])) { $updates['author'] = pwg_db_real_escape_string($photo['owner']['username']); } if (in_array('fill_description', $photo['fills'])) { $updates['comment'] = pwg_db_real_escape_string(@$photo['description']); } if (in_array('fill_geotag', $photo['fills']) and !empty($photo['location'])) { $updates['latitude'] = pwg_db_real_escape_string($photo['location']['latitude']); $updates['longitude'] = pwg_db_real_escape_string($photo['location']['longitude']); } if (in_array('level', $photo['fills']) && !$photo['visibility']['ispublic']) { $updates['level'] = 8; if ($photo['visibility']['isfamily']) { $updates['level'] = 4; } if ($photo['visibility']['isfriend']) { $updates['level'] = 2; } } if (count($updates)) { single_update(IMAGES_TABLE, $updates, array('id' => $photo['image_id'])); } if (!empty($photo['tags']['tag']) and in_array('fill_tags', $photo['fills'])) { $raw_tags = array_map(create_function('$t', 'return $t["_content"];'), $photo['tags']['tag']); $raw_tags = implode(',', $raw_tags); set_tags(get_tag_ids($raw_tags), $photo['image_id']); } } return l10n('Photo "%s" imported', $photo['title']); }
/** * 收到图片消息时触发,回复由收到的图片组成的图文消息 * * @return void */ protected function onImage() { $saved_path = download_remote_file($this->getRequest('picurl')); $cmd = "../cpp/calc " . $saved_path; $result_name = exec($cmd); $result_url = "http://" . $_SERVER['HTTP_HOST'] . "/scorgen/" . $result_name; $this->responseText($result_url); }
function post($a, $b) { $link = mysqli_connect('endpoint', 'user', 'password', 'database'); //Ask for credentials if (!$link) { die('Could not connect: ' . mysql_error()); } $sql = "INSERT INTO samples (user, filename)\n\tVALUES ('" . $a . "', '" . $b . "')"; if (mysqli_query($link, $sql)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($link); } download_remote_file('bucket' . $b . '.jpg', realpath("/var/www/html") . '/photo.jpg'); //Ask for bucket exec('g++ -o test2 test2.cpp 2>&1', $output, $return_value); //run a test C++ script exec('./test2 work please', $output, $return_value); //print the output the test script returns echo ($return_value == 0 ? 'OK' : 'Error: status code ' . $return_value) . PHP_EOL; echo 'Output: ' . PHP_EOL . implode(PHP_EOL, $output); }
<?php function download_remote_file($file_url, $save_to) { $content = file_get_contents($file_url); file_put_contents($save_to, $content); } download_remote_file('http://www.boi.org.il//he/DataAndStatistics/Lists/BoiTablesAndGraphs/itrchovh.xls', realpath("./xls_data") . '/overdraft.xls'); require_once 'PHPExcel/Classes/PHPExcel.php'; //Usage: convertXLStoCSV('xls_data/overdraft.xls', '../data/overdraft.csv'); function convertXLStoCSV($infile, $outfile) { $fileType = PHPExcel_IOFactory::identify($infile); $objReader = PHPExcel_IOFactory::createReader($fileType); $objReader->setReadDataOnly(true); $objPHPExcel = $objReader->load($infile); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV'); $objWriter->save($outfile); }
download_remote_file(IDROMETRIA_Ombrone_PonteAlleVanne, dirname(__FILE__) . "/data/IDROMETRIA_Ombrone_PonteAlleVanne.jpg", $logfile); download_remote_file(IDROMETRIA_Ombrone_PoggioACaiano, dirname(__FILE__) . "/data/IDROMETRIA_Ombrone_PoggioACaiano.jpg", $logfile); download_remote_file(PLUVIOMETRIA_Prato_Città, dirname(__FILE__) . "/data/PLUVIOMETRIA_Prato_Città.jpg", $logfile); download_remote_file(PLUVIOMETRIA_Prato_Università, dirname(__FILE__) . "/data/PLUVIOMETRIA_Prato_Università.jpg", $logfile); download_remote_file(PLUVIOMETRIA_Galceti_Montemurlo, dirname(__FILE__) . "/data/PLUVIOMETRIA_Galceti_Montemurlo.jpg", $logfile); download_remote_file(PLUVIOMETRIA_Vaiano_Gamberame, dirname(__FILE__) . "/data/PLUVIOMETRIA_Vaiano_Gamberame.jpg", $logfile); download_remote_file(PLUVIOMETRIA_Vaiano_Acquedotto, dirname(__FILE__) . "/data/PLUVIOMETRIA_Vaiano_Acquedotto.jpg", $logfile); download_remote_file(PLUVIOMETRIA_Fattoria_Iavello_Montemurlo, dirname(__FILE__) . "/data/PLUVIOMETRIA_Fattoria_Iavello_Montemurlo.jpg", $logfile); download_remote_file(PLUVIOMETRIA_Cantagallo, dirname(__FILE__) . "/data/PLUVIOMETRIA_Cantagallo.jpg", $logfile); download_remote_file(TERMOMETRIA_Prato_Università, dirname(__FILE__) . "/data/TERMOMETRIA_Prato_Università.jpg", $logfile); download_remote_file(TERMOMETRIA_Galceti_Montemurlo, dirname(__FILE__) . "/data/TERMOMETIRIA_Galceti_Montemurlo.jpg", $logfile); download_remote_file(ANEMOMETRIA_Prato_Università, dirname(__FILE__) . "/data/ANEMOMETRIA_Prato_Università.jpg", $logfile); download_remote_file(ANEMOMETRIA_Galceti_Montemurlo, dirname(__FILE__) . "/data/ANEMOMETRIA_Galceti_Montemurlo.jpg", $logfile); download_remote_file(IGROMETRIA_Prato_Città, dirname(__FILE__) . "/data/IGROMETRIA_Prato_Città.jpg", $logfile); download_remote_file(IGROMETRIA_Galceti_Montemurlo, dirname(__FILE__) . "/data/IGROMETRIA_Galceti_Montemurlo.jpg", $logfile); download_remote_file(IGROMETRIA_Vaiano_Acquedotto, dirname(__FILE__) . "/data/IGROMETRIA_Vaiano_Acquedotto.jpg", $logfile); function download_remote_file($file_url, $save_to, $logfile) { $today = date("Y-m-d H:i:s"); $content = file_get_contents($file_url); file_put_contents($save_to, $content); $log = $today . ";" . $save_to . " salvato\n"; file_put_contents($logfile, $log, FILE_APPEND | LOCK_EX); } function store($xmlFile, $dest, $logfile) { $today = date("Y-m-d H:i:s"); if (!simplexml_load_file($xmlFile)) { print $xmlFile . " non correttamente scaricato\r\n"; $log = $today . ";" . $xmlFile . " non correttamente scaricato\n"; file_put_contents($logfile, $log, FILE_APPEND | LOCK_EX);