0

我正在尝试在我的网站中实现 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.';

    }

在输出结果中我得到“1”,这表明没有错误,但我在附件文件夹中找不到上传的文件。

我也尝试使用public_path()函数查找附件文件夹,但后来我得到了500 error. 附件文件夹的权限也设置为777

4

1 回答 1

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); 
        }
于 2014-12-28T15:34:38.627 回答