Skip to content

Instantly share code, notes, and snippets.

@Leechael
Created April 28, 2014 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Leechael/11362915 to your computer and use it in GitHub Desktop.
Save Leechael/11362915 to your computer and use it in GitHub Desktop.
<?php
use Symfony\Component\HttpFoundation\File\UploadedFile;
class SmokeTestingController extends \BaseController
{
public function upload()
{
$iniMax = strtolower(ini_get('upload_max_filesize'));
if ('' === $iniMax) {
$iniMax = PHP_INT_MAX;
}
$r = [
"php" => [
"file_uploads" => (ini_get("file_uploads") === "1"),
"upload_max_filesize" => $iniMax,
"max_file_uploads" => ini_get("max_file_uploads"),
"post_max_size" => ini_get("post_max_size"),
"max_input_time" => ini_get("max_input_time"),
"session.gc_maxlifetime" => ini_get("session.gc_maxlifetime"),
"session.upload_progress.enabled" => ini_get("session.upload_progress.enabled"),
],
];
if ($file = Input::file("file")) {
if (!$file->isValid()) {
$r["error"] = $file->getErrorMessage();
} else {
$r["file"] = [
"server" => [
"size" => $file->getSize(),
"mimetype" => $file->getMimeType(),
"extension" => $file->guessExtension(),
],
"client" => [
"name" => $file->getClientOriginalName(),
"size" => $file->getClientSize(),
"extension" => $file->getClientOriginalExtension(),
"mimetype" => $file->getClientMimeType(),
],
];
}
} else {
$r["error"] = "Please upload file with field name `file`.";
}
if ($begin = Input::get("begin")) {
$elapsed = time() - $begin;
$r["elapsed"] = $elapsed . "s";
if ($size = array_get($r, "file.sever.size")) {
$r["speed"] = $size / $elapsed;
}
}
return Response::json($r);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment