我无法找到文件,我上传了,它不在应该是的文件夹中。我不知道该怎么办。 IT表示上传已正确完成,并且在控制台中没有任何错误。
<form action="upload.php" class="dropzone" id="my-awesome-dropzone">
<input type="file" name="file" />
<button type="submit">Send</button>
</form>
有PHP
<?php
function post_upload()
{
$input = Input::all();
$rules = array(
'file' => 'image|max:3000'
);
$validation = Validator::make($input, $rules);
if ($validation->fails()) {
return Response::make($validation->errors->first(), 400);
}
$file = Input::file('file');
$extension = File::extension($file['name']);
$directory = 'uploads/' . sha1(time());
echo ($directory);
$filename = sha1(time() . time()) . ".{$extension}";
$upload_success = Input::upload('file', $directory, $filename);
if ($upload_success) {
return Response::json('success', 200);
} else {
return Response::json('error', 400);
}
}
post_upload();
?>
文件夹有权写入。
答案 0 :(得分:0)
我不确定您的代码有什么问题,但您可以尝试我的工作解决方案:
$ds = DIRECTORY_SEPARATOR;
$store_folder = 'uploads';
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ).$ds.$store_folder.$ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
}