0

I'm trying to implement Uploadifive plugin into my website but I don't see the files which are uploaded. I don't see any errors. Here is my code:

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.';

    }

On output I get "1" as result, which indicated there is not errors, but I can't find uploaded file in attachments folder.

I also tried to find attachments folder using public_path() function but then I get 500 error. Also permissions of attachments folder is set to 777

Alen
  • 1,750
  • 7
  • 31
  • 62

1 Answers1

0

try:

$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); 
        }
Lonare
  • 3,581
  • 1
  • 41
  • 45