0

I'm tring upload an image on wordpress front end. I built my form where there is:

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

And then on click, starts this jquery code:

jQuery('#upload_temp_image_results').load(pathname, {'image': jQuery('#choose_file').val()});

Finally the uploader.php:

if (!function_exists('wp_handle_upload')) require_once('../../../../wp-admin/includes/file.php');

    $image = $_POST['image'];
    $expire = $_POST['expire'];
    echo 'a<img src="'.$image.'"/>a';
    echo $image;
    echo $expire;

    $movefile = wp_handle_upload($image, array( 'test_form' => false ));
    if ($movefile) 
    {
        echo "File is valid, and was successfully uploaded.\n";
        var_dump( $movefile);
    } 
    else 
    {
        echo "Possible file upload attack!\n";
    }

My problem is that i get this error:

Fatal error: Call to undefined function __() in C:\xampp\htdocs\cancellare\wp-admin\includes\file.php on line 13

What's wrong? I need to use my custom form and i can't use wordpress uploader (which is used in admin area).

aggenerale
  • 15
  • 3
  • You cannot upload a file like that see http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously-with-jquery – Musa Sep 28 '13 at 17:29
  • Wordpress has a perfectly good media uploader already built in. Learn to use that instead. – adeneo Sep 28 '13 at 17:30
  • Musa: thanks.i didn't find before that link! – aggenerale Sep 28 '13 at 21:21
  • Adeneo: i'm able to use wp media uploader, but as i wrote in my post, "I need to use my custom form and i can't use wordpress uploader" – aggenerale Sep 28 '13 at 21:22

1 Answers1

0

To use WP functions, u must to load wp-load.php from root folder of ur wordpress install. And only then, if it's not allready included by wp-load.php, u must include such file's as file.php

c0ns0l3
  • 66
  • 2
  • Ok, it works! I'd like to undestand better: what's wp-load.php content? – aggenerale Sep 28 '13 at 21:54
  • wp-load.php loading all WP functionality. In ur case, error calling **__()** function - l10n function from translate WP. After WP-Load.php u can use all WP functions and variables, such as $wp_query, $wp_db and else. – c0ns0l3 Sep 29 '13 at 07:45