我试图测试上传API,但每次都失败:
测试代码:
$JSONResponse = $this->call('POST', '/upload', [], [], [
'photo' => new UploadedFile(base_path('public/uploads/test') . '/34610974.jpg', '34610974.jpg')
]);
$this->assertResponseOk();
$this->seeJsonStructure(['name']);
$response = json_decode($JSONResponse);
$this->assertTrue(file_exists(base_path('public/uploads') . '/' . $response['name']));
Run Code Online (Sandbox Code Playgroud)
文件路径是/public/uploads/test/34610974.jpg
这是控制器中的My Upload代码:
$this->validate($request, [
'photo' => 'bail|required|image|max:1024'
]);
$name = 'adummyname' . '.' . $request->file('photo')->getClientOriginalExtension();
$request->file('photo')->move('/uploads', $name);
return response()->json(['name' => $name]);
Run Code Online (Sandbox Code Playgroud)
我应该如何在Laravel 5.2中测试文件上传?如何使用call方法上传文件?
我有4个文件输入,我希望它们的值在更改时触发上传进程.我的意思是当您选择图片并单击选择图像对话框上的打开时,将触发上传图片的脚本.我使用过onchange事件,但我认为这不是正确的事件:
JS:
$("input[type=file]").on('change',function(){
alert(this.val());//I mean name of the file
});
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="form-group col-md-11 col-md-offset-1">
<input type="file" name="photos[]">
<input type="file" name="photos[]">
<input type="file" name="photos[]">
<input type="file" name="photos[]">
</div>
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我最近安装了laravel并在/ tests目录中编写了一些测试,但是当我phpunit在cmd中使用同一个文件夹phpunit.xml时,它说'phpunit' is not recognized as an internal or external command,operable program or batch file..我正在使用Windows 7.我该怎么办?
我是java 多线程编程的新手.我想到的问题是我可以根据CPU核心数运行多少个线程.如果我运行线程超过CPU核心将是机器运行应用程序的开销.例如,当我们有一台服务器机器,它有一个运行2个线程的服务器软件(主线程+开发人员线程)时,当更多的同时客户端与服务器建立套接字连接时,它是否会成为服务器的开销?
谢谢.
我想使用Elasticsearch PHP API查询多个类型和索引.但我不知道怎么做.我应该传递一系列类型和索引$params吗?:
$params['index'] = $index;//array of indices
$params['type'] = $types;//array of types
$params['body'] = $q;//query body
//request elasticsearch for matched documents
$results = $client->search($params);
Run Code Online (Sandbox Code Playgroud) 我正在使用Google Web Fonts.除IE9外,所有浏览器都正确呈现字体.(我没有在早期版本的IE上测试过).
HTML:
<head>
<link href='http://fonts.googleapis.com/css?family=Yeseva+One' rel='stylesheet' type='text/css'>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/vendor/modernizr-2.6.2.min.js"></script>
</head>
Run Code Online (Sandbox Code Playgroud)
Google字体文件内容:
@font-face {
font-family: 'Yeseva One';
font-style: normal;
font-weight: 400;
src: local('Yeseva One'),
local('YesevaOne'),
url(http://themes.googleusercontent.com/static/fonts/yesevaone/v6/wVgDKaRrT3DN9VGcOY4orxsxEYwM7FgeyaSgU71cLG0.woff) format('woff');
}
Run Code Online (Sandbox Code Playgroud)
CSS:
.sf-menu li {
float:left;
position:relative;
text-align:center;
font-family:'Yeseva One',cursive;
font-size:17px;
line-height: 64px;
border-bottom:1px solid #4A4A4A;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
我想在javascript中使用正则表达式从img标签中提取图像名称.我的问题是console.log()抛出异常:TypeError: pattern.exec is not a function.
JS:
$("label.btn-danger").on('click',function(e){
e.preventDefault();
var src = $(this).parents("label").find("img").attr("src");
var pattern = "/\/([A-Z0-9_-]{1,}\.(?:png|jpg|gif|jpeg))/ig";
var result = pattern.exec(src)
console.log(result);
});
Run Code Online (Sandbox Code Playgroud) 我想更新数据库中的JSON列,但出现此错误:
Array to string conversion
Run Code Online (Sandbox Code Playgroud)
我已经array在模型中声明了列名:
protected $casts = [
'destinations' => 'array'
];
Run Code Online (Sandbox Code Playgroud)
这是我使用的代码:
$data[] = [
'from' => $fromArray,
'to' => $toArray
];
Flight::where('id', $id)->update(['destinations' => $data]);
Run Code Online (Sandbox Code Playgroud)
我该怎么办 ?
我想在文本输入字段中处理更改事件.但是当鼠标失去对元素的关注时会触发事件.我希望触发as-type-in change事件.我应该怎么做jQuery中的直播活动?
我用过:
jQuery('#element').on('change',function(){
//do the stuff
});
Run Code Online (Sandbox Code Playgroud) 我正在MongoDB中进行聚合,它的$projectstage应该有一个数组字段投影。但我无法通过它们的索引访问数组字段:
{//projection stage
$project: {
'foo' : { '$ifNull' : ['$bar.0.baz.0.qux', '*'] }
}
}
Run Code Online (Sandbox Code Playgroud)
这设置foo为一个空数组。bar 是一个多维数组字段。我的 MongoDB 版本是 3.2 。如果没有$unwind/$group旧的繁重解决方案的麻烦,我该怎么办?
谢谢你的帮助 。