我尝试在我的网站上实施Uploadifive插件,但我没有看到上传的文件。我没有看到任何错误。这是我的代码:
HTML
<div class="form-group" id="queue">
<label for="file">Add attachment</label>
{{ Form::file("file", ["id" => "file_upload", "multiple" => true]) }}
<a style="position: relative; top: 8px;" href="javascript:$('#file_upload').uploadifive('upload')">Upload Files</a>
</div>
JS
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadifive({
'auto' : true,
'queueID' : 'queue',
'uploadScript' : "/uploadfive/uploadifive.php",
'onUploadComplete' : function(file, data) { console.log(data); }
});;
});</script>
PHP
$uploadDir = "/public_html/myDomain.com/public/attachments/";
// Set the allowed file extensions
$fileTypes = array('jpg', 'jpeg', 'gif', 'png'); // Allowed file extensions
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
$tempFile = $_FILES['Filedata']['tmp_name'];
$uploadDir = $_SERVER['DOCUMENT_ROOT'] . $uploadDir;
$targetFile = $uploadDir . $_FILES['Filedata']['name'];
// Validate the filetype
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array(strtolower($fileParts['extension']), $fileTypes)) {
// Save the file
move_uploaded_file($tempFile, $targetFile);
echo 1;
} else {
// The file type wasn't allowed
echo 'Invalid file type.';
}
在输出时我得到&#34; 1&#34;结果表明没有错误,但我无法在附件文件夹中找到上传的文件。
我还尝试使用public_path()
函数找到附件文件夹,但后来我得到了500 error
。附件文件夹的权限也设置为777
答案 0 :(得分:0)
尝试:
$file = Input::file('file');
$destinationPath = public_path().'/files';
// If the uploads fail due to file system, you can try doing public_path().'/uploads'
$filename = str_random(12);
//$filename = $file->getClientOriginalName();
//$extension =$file->getClientOriginalExtension();
$upload_success = Input::file('file')->move($destinationPath, $filename);
if( $upload_success ) {
return Response::json('success', 200);
} else {
return Response::json('error', 400);
}