Superpupsi
Superpupsi

Reputation: 87

Slim Framework with Paris / Idiorm / Twig - How to handle Fileuploads?

Jep, thats the Question. How to handle Fileuplaods via this nice Team?

Something like:

$app -> post('/new/', function() use ($app) {
    $photo = Model::factory('Photos') -> create();      
    $unique_id = md5(uniqid(rand(), true));
    $WORKSPACE = 'data/photos/';
    $media = $HTTP_POST_FILES['photo']['name'];
    $filetype = strrchr($media,'.');
    $new_upload = $WORKSPACE . $unique_id . $filetype;
    $the_upload = copy($HTTP_POST_FILES['photo']['tmp_name'], $new_upload);
    $uploaded_file   = $new_upload;
    @chmod($uploaded_file, 0777);

    $photo -> timestamp = date('Y-m-d H:i:s');
    $photo -> url = 'data/photos/' . $unique_id . $filetype;
    $photo -> new_picture = $unique_id . $filetype;
    $photo -> description = $app -> request() -> post('description');
    $photo -> save();
    $app -> redirect('/upload/');
});

Will not work, cause:

Slim Application Error: Message: Undefined variable: HTTP_POST_FILES

But how can i access a fileupload field like:

<input type="file" name="photo" value="" id="photo" />

via Slim?

Upvotes: 0

Views: 2334

Answers (1)

jpic
jpic

Reputation: 33420

$HTTP_POST_FILES is not a superglobal. It is out of the scope of your function.

You should use $_FILES instead, also because $HTTP_POST_FILES is deprecated.

Upvotes: 4

Related Questions