Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Trying to get Uploadify to work together with Wordpress. I've implented the code from documentation in a metabox in wordpress admin area.

I can "select file" and upload it, and Uploadify will show progress, but when I check the destination folder, it's empty. The folder has chmod 777 so I don't understand what could be wrong..

All help appreciated.

<link href="<?php echo get_stylesheet_directory_uri() ?>/uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/uploadify/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/uploadify/swfobject.js"></script>
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '<?php echo get_stylesheet_directory_uri() ?>/uploadify/uploadify.swf',
'script' : '<?php echo get_stylesheet_directory_uri() ?>/uploadify/uploadify.php',
'cancelImg' : '<?php echo get_stylesheet_directory_uri() ?>/uploadify/cancel.png',
'folder' : '<?php echo get_bloginfo('url') ?>/wp-content/uploads',
'auto' : true
});
});
</script>

<input id="file_upload" name="file_upload" type="file" />

Uploadify.php

<?php
/*
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

    // $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes  = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts  = pathinfo($_FILES['Filedata']['name']);

    // if (in_array($fileParts['extension'],$typesArray)) {
        // Uncomment the following line if you want to make the directory if it doesn't exist
        // mkdir(str_replace('//','/',$targetPath), 0755, true);

        move_uploaded_file($tempFile,$targetFile);
        echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
    // } else {
    //  echo 'Invalid file type.';
    // }
}
?>
share|improve this question
    
Please provide the PHP code as well. –  hakre Mar 21 '11 at 1:53
    
Updated. It's the standard uploadify.php that comes with the install. –  INT Mar 21 '11 at 8:16
add comment

1 Answer 1

up vote 1 down vote accepted

your uploadify.php is all inside a comment so its not really saving the file.

change it with this:

<?php
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];

    $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
    $fileTypes  = str_replace(';','|',$fileTypes);
    $typesArray = split('\|',$fileTypes);
    $fileParts  = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$typesArray)) {
        // Uncomment the following line if you want to make the directory if it doesn't exist
        // mkdir(str_replace('//','/',$targetPath), 0755, true);

        move_uploaded_file($tempFile,$targetFile);
        echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
    } else {
        echo 'Invalid file type.';
    }
}
?>

and also make sure you validate the file type because i had a site hacked after a hacker uploaded a php shell script with uploadify.

share|improve this answer
    
Oh, didn't realize, thought it was all optional. It didn't change anything however, still not uploading although it shows full progress and "completed" –  INT Mar 21 '11 at 13:49
    
@INT: the full progress and "completed" you are seeing is the file gets sent to the server but noting is done with it so its not saved. –  Bainternet Mar 21 '11 at 15:33
    
I meant: I replaced the code in my uploadify.php with the one you pasted above. And still it doesn't save the image. Wasn't the code you pasted supposed to make it save the upload? Thanks for your help! –  INT Mar 21 '11 at 15:56
    
@INT: you need to specify file types for example: 'fileExt' : '*.jpg;*.gif;*.png', –  Bainternet Mar 21 '11 at 21:38
1  
@INT: change your code with this pastie.org/1697617 –  Bainternet Mar 21 '11 at 22:33
show 5 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.