Created
April 20, 2013 14:03
-
-
Save erikaheidi/5426089 to your computer and use it in GitHub Desktop.
upload test with silex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__.'/vendor/autoload.php'; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\Response; | |
$app = new Silex\Application(); | |
$app['debug'] = true; | |
$app->get('/', function () use ($app) { | |
$form = '<h2>Silex Form Upload Test</h2>'; | |
$form .= '<form method="post" action="/silex/upload" enctype="multipart/form-data">'; | |
#$form .= '<input type="hidden" name="MAX_FILE_SIZE" value="500">'; | |
$form .= '<input type="file" name="file" />'; | |
$form .= '<input type="submit" value="Submit"/>'; | |
return $form; | |
}); | |
$app->post('/upload', function (Request $request) use ($app) { | |
$file = $request->files->get('file'); | |
if ($file !== null) { | |
$path = 'uploads/'; | |
$file->move($path, $file->getClientOriginalName()); | |
$response = "file uploaded successfully: " . $file->getClientOriginalName(); | |
$response .= '<br>size: ' . filesize($path . '/' . $file->getClientOriginalName()) / 1024 . ' kb'; | |
return new Response($response); | |
} else { | |
return new Response("An error ocurred. Did you really send a file?"); | |
} | |
}); | |
$app->get('/phpinfo', function () use ($app) { | |
phpinfo(); | |
exit; | |
}); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment