user1425871
user1425871

Reputation: 149

uploadify works but does not upload into the folder

I am using uploadify although it works it does not upload into the folder. How can I make it copy? The folder is 777.

here is the page if needed:

http://www.dilyurdu.com/uploadify/

// script

$(function() {

$("#file_upload_1").uploadify({
    height        : 30,
    swf           : 'uploadify.swf',
    uploader      : 'uploadify.php',
    width         : 120
});
});

//php

$targetFolder = '/uploads'; // Relative to the root

if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];

// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array($fileParts['extension'],$fileTypes)) {
    move_uploaded_file($tempFile,$targetFile);
    echo '1';
} else {
    echo 'Invalid file type.';
}
}   

Upvotes: 0

Views: 4731

Answers (4)

nasouh
nasouh

Reputation: 1

the problem was with the path of upload folder my path:

$targetFolder = '../../upload/orginal'; // Relative to the root

Upvotes: 0

willothewisp
willothewisp

Reputation: 5

I had the same problem. After trying everything mentioned in this post, and other posts on the subject, I realised that I had to set an absolute path to the target folder. So, what worked for me was to change the following in uploadify.php:

$targetFolder = '/var/www/vhosts/DOMAIN/httpdocs/uploads'

Then I removed the DOCUMENT_ROOT FROM $targetPath to just leave $targetFolder, as follows: $targetPath = $targetFolder;

I also added the timestamp and token to my JS call, as above.

Everything works now. Hope this helps someone :-)

Upvotes: 0

todd
todd

Reputation: 365

I tried all of the other suggestions here, but none of them worked for me. Then I realized that version 3.2 of Uploadify (and maybe previous versions, too) requires a timestamp and hashed token in order to complete the upload.

First off, I had to move the script from an external JS file to my PHP file so that I could get the timestamp from PHP. (You could also do this via a hidden input value or other method, but this was the simplest way.) Then I had to add the 'formData' option to my Uploadify call along with some PHP code that gets the timestamp and hashes it with a unique salt (which you should change to a random string):

<?php $timestamp = time();?>
<script>
$('#file_upload').uploadify({
    'swf'      : '/uploadify/uploadify.swf',
    'uploader' : '/uploadify/uploadify.php',
    'formData' : {
        'timestamp' : '<?php echo $timestamp;?>',
        'token'     : '<?php echo md5("unique_salt" . $timestamp);?>'
    }
});
</script>

Although this code seems to be required in version 3.2, it is not mentioned in the implementation documentation. I had to look in the index.php file that came in the download package to find it.

Upvotes: 0

Vamsi
Vamsi

Reputation: 873

Try this

<script type="text/javascript">
$(document).ready(function() {
 $(function() {
    $("#file_upload").uploadify({
            'uploader'       : '<?php echo base_url();?>flash/uploadify.swf',
            'script'         : '<?php echo base_url();?>scripts/uploadify.php',
            'folder'         : '/folder_name_where_you_want_to_upload/',
            'height'         : 30,
            'onError'        : function(event,queueID,fileObj,errorObj){
                    // alert(errorObj["type"]+" - "+errorObj["status"]+" - "+errorObj["text"]);
             },
            });
    });
});
</script>

And also echo $targetPath in uploadify.php so that you can trace the path where it is being uploaded.

Upvotes: 2

Related Questions