function combine_and_upload($id) { $files = array(); $photo_count = $_SESSION['photo_number_' . $id]; for ($i = 1; $i <= $photo_count; $i++) { $files[] = PHOTO_PATH . $id . '_' . $i . '.jpeg'; } // combine photos into one file and upload if ($combined_file = combine_photos($files)) { $result = upload_photo($combined_file); $facebook_id = array_val($result, 'id'); if (empty($facebook_id)) { error_log('Failed to upload to Facebook: ' . print_r($result, 1)); } // send the combined file back to the client regardless of success echo json_encode(array('photo_src' => PUBLIC_PHOTO_PATH . basename($combined_file), 'facebook_id' => $facebook_id)); if (THE_B0XX_URL) { notify_the_b0xx($facebook_id); } // "Uploaded photo: http://www.facebook.com/photo.php?fbid={$result['id']}\n"; } }
function execute_action($action) { switch ($action['type']) { case 'post_quote': // upload_random_quote($user); // choose a image that wasn't already posted for user $image = $this->db->from('images')->where("id NOT IN (SELECT image_id FROM person_images WHERE person_id= ?)", $action['person_id'])->orderBy('RAND()')->limit(1)->fetch(); // 'fetch' is to get only one, not array $this->post_image(QUOTES_PATH . $image['filename'], $action['social_network']); break; case 'post_photo': // read one file order by name // post file to social netowork upload_photo($action['link']); // move file to uploaded folder break; case 'post_link': upload_image($action['link']); break; default: break; } }
function generate_skill_array($title_post, $detail_post, $file_post, $old_skill) { $skill = array(); $skill['title'] = filter_var($_POST[$title_post], FILTER_SANITIZE_STRING); $skill['detail'] = filter_var($_POST[$detail_post], FILTER_SANITIZE_STRING); //if basename is nil we need to use the old photo $skill['photo'] = basename($_FILES[$file_post]['name']); if (strlen($skill['photo']) < 3) { //if no new photo use the old one $old_skill = json_decode($old_skill, true); $skill['photo'] = $old_skill['photo']; } else { //Save the new photo to img dir upload_photo($_FILES[$file_post]); } return $skill; }
for ($count = 0; $count < $data_arr_len; $count++) { $message = $data_arr[$count]["message"]; $object_id = $data_arr[$count]["object_id"]; $sql = "SELECT COUNT(obj_id) FROM beauty WHERE obj_id = :object_id"; $stmt = $link->prepare($sql); $stmt->execute(array(":object_id" => $object_id)); if ($stmt->fetchColumn() !== 0) { break; } if (mb_stristr($message, "正妹") === false) { continue; } save_binary_file("https://graph.facebook.com/" . $object_id . "/picture?type=normal"); upload_photo("temp.jpg", $message); save_binary_file("https://graph.facebook.com/" . $object_id . "/picture?type=thumbnail"); upload_photo("temp.jpg", $message); $sql = "INSERT INTO beauty(message,obj_id) VALUES(:message,:obj_id)"; try { $stmt = $link->prepare($sql); $stmt->execute(array(":message" => $message, ":obj_id" => $object_id)); } catch (PDOException $e) { //check duplicate entries. if ($e->errorInfo[0] == '23000' && $e->errorInfo[1] == '1062') { if (file_exists("error_log.log")) { @unlink("error_log.log"); } file_put_contents("error_log.log", "Duplicate data\r\n"); } else { file_put_contents("error_log.log", "Other errors.\r\n"); } }
public function do_photo() { //文件上传 $file = $_FILES['file']['name']; if (!empty($file)) { $upload = upload_photo($_POST); $m = D("Admin"); $where['id'] = $_SESSION['id']; if ($upload['success'] == '1') { //文件上传成功 $m->admin_pic = $upload['url']; $res = $m->where($where)->save(); if ($res) { $this->success('修改成功'); } else { $this->error('修改失败'); } } else { //文件上传失败 $this->error($upload['error']); } } else { $this->error('头像没有更改,请上传新图片!'); } }
function post_edit() { if (isset($_SESSION["user_id"])) { $post_id = $_POST["id"]; $post_title = isset($_POST["title"]) ? $_POST["title"] : ""; $post_body = isset($_POST["body"]) ? $_POST["body"] : ""; $post_tags = isset($_POST["tags"]) ? $_POST["tags"] : ""; $post_privacy = isset($_POST["privacy"]) ? $_POST["privacy"] : ""; $post_status = isset($_POST["status"]) ? $_POST["status"] : ""; if ($post_privacy != "" && $post_status != "") { $mysqli = db_connect(); $mysqli->query("UPDATE Posts SET" . " UserId = '" . $mysqli->real_escape_string($_SESSION["user_id"]) . "'" . ", Title = '" . $mysqli->real_escape_string($post_title) . "'" . ", Body = '" . $mysqli->real_escape_string($post_body) . "'" . ", Privacy = '" . $mysqli->real_escape_string($post_privacy) . "'" . ", Status = '" . $mysqli->real_escape_string($post_status) . "'" . ", Edited = NOW()" . ", IPEdited = '" . $mysqli->real_escape_string($_SERVER["REMOTE_ADDR"]) . "'" . " WHERE Id=" . $mysqli->real_escape_string($post_id)); // do we have a photo ? upload_photo($post_id, $mysqli); // remove the existing post tags $mysqli->query("DELETE FROM PostTags WHERE PostId=" . $mysqli->real_escape_string($post_id)); // break the tags up into individual terms $tags = explode(",", $post_tags); if (count($tags) > 0) { // trim all tags $tags = array_map("trim", $tags); foreach ($tags as $tag) { if ($tag != "") { $tag = strtolower($tag); $tag_id = 0; // find out if the tag exists $sql = "SELECT * FROM Tags WHERE Name='" . $mysqli->real_escape_string($tag) . "'"; $result = $mysqli->query($sql); if ($result->num_rows > 0) { // if it does exist, get it's ID $row = @$result->fetch_assoc(); $tag_id = $row["Id"]; } else { // if it does not exist, add it, and get the ID $sql = "INSERT INTO Tags (Name) VALUES ('" . $mysqli->real_escape_string($tag) . "')"; $mysqli->query($sql); $tag_id = $mysqli->insert_id; } // add the tag to the PostTags list $mysqli->query("INSERT INTO PostTags (PostId,TagId,Created) VALUES (" . $mysqli->real_escape_string($post_id) . "," . $mysqli->real_escape_string($tag_id) . ",Now())"); } } } return $post_id; } else { return -1; } } else { header("Location: /401"); } }