Пример #1
0
        $app->response()->body(json_encode(array('location' => $r['location'], 'error' => $r['error'])));
    }
});
$app->post('/photo', function () use($app) {
    if ($user = require_login($app)) {
        // var_dump($app->request()->post());
        //
        // Since $app->request()->post() with multipart is always
        // empty (bug in Slim?) We're using the raw $_POST here
        // until this gets fixed.
        // PHP empties everything in $_POST if the file upload size exceeds
        // that is why we have to test if the variables exist first.
        $note_content = isset($_POST['note_content']) ? $_POST['note_content'] : null;
        $params = array('note_content' => $note_content);
        $file = isset($_FILES['note_photo']) ? $_FILES['note_photo'] : null;
        $r = create_photo($user, $params, $file);
        // Populate the error if there was no location header.
        if (empty($r['location']) && empty($r['error'])) {
            $r['error'] = "No 'Location' header in response.";
        }
        $html = render('photo', array('title' => 'Photo posted', 'note_content' => $params['note_content'], 'location' => isset($r['location']) ? $r['location'] : null, 'error' => isset($r['error']) ? $r['error'] : null, 'response' => isset($r['response']) ? htmlspecialchars($r['response']) : null, 'authorizing' => false));
        $app->response()->body($html);
    }
});
$app->post('/repost', function () use($app) {
    if ($user = require_login($app)) {
        $params = $app->request()->params();
        $r = create_repost($user, $params['url']);
        $app->response()->body(json_encode(array('location' => $r['location'], 'error' => $r['error'])));
    }
});
Пример #2
0
require 'main.php';
function create_photo($file_path, $orig_name)
{
    # Upload the received image file to Cloudinary
    $result = \Cloudinary\Uploader::upload($file_path, array("tags" => "backend_photo_album", "public_id" => $orig_name));
    unlink($file_path);
    error_log("Upload result: " . \PhotoAlbum\ret_var_dump($result));
    $photo = \PhotoAlbum\create_photo_model($result);
    return $result;
}
$files = $_FILES["files"];
$files = is_array($files) ? $files : array($files);
$files_data = array();
foreach ($files["tmp_name"] as $index => $value) {
    array_push($files_data, create_photo($value, $files["name"][$index]));
}
?>
<html>
<head>
    <link href="style.css" media="all" rel="stylesheet"/>
    <title>Upload succeeded!</title>
</head>
<body>

<h1>Your photo has been uploaded sucessfully!</h1>
<h2>Upload details:</h2>
<?php 
foreach ($files_data as $file_data) {
    \PhotoAlbum\array_to_table($file_data);
}
require 'main.php';
function create_photo($file_path)
{
    # Upload the received image file to Cloudinary
    $result = \Cloudinary\Uploader::upload($file_path, array("tags" => "backend_photo_album"));
    unlink($file_path);
    error_log("Upload result: " . \PhotoAlbum\ret_var_dump($result));
    $photo = \PhotoAlbum\create_photo_model($result);
    return $result;
}
$files = $_FILES["files"];
$files = is_array($files) ? $files : array($files);
$files_data = array();
foreach ($files["tmp_name"] as $index => $value) {
    array_push($files_data, create_photo($value));
}
?>
<html>
	<head>
		<link href="style.css" media="all" rel="stylesheet" />
		<title>Upload succeeded!</title>
	</head>
  <body>
  	
    <h1>Your photo has been uploaded sucessfully!</h1>
    <h2>Upload details:</h2>    
    <?php 
foreach ($files_data as $file_data) {
    \PhotoAlbum\array_to_table($file_data);
}