Reading a file uploade in my module without saving it I'm creating an module and there I want to read a text file. 

I don't want to save the file.

In my my_module.module file I have

function my_module_upload_form($form, &amp;$form_state) {
    $form['upload'] = array(
        '#type' =&gt; 'file',
    );

    $form['submit_button'] = array(
        '#type' =&gt; 'submit',
        '#value' =&gt; t('Upload'),
    );

    return $form;
}
function my_module_upload_form_submit($form, &amp;$form_state) {
    $file = file_load($form_state['values']['upload']);
    $url = file_create_url($file-&gt;uri);
}


I get the error "Trying to get property of non-object" at 

$url = file_create_url($file-&gt;uri);


Can someone point me how to read the file correctly (without saving it)?
Ok I figured it out myself!

function my_module_upload_form_submit($form, &amp;$form_state) {
    //saved the file into a tmp folder (location to save not set)
    //this will also add a pointer in the database
    $file = file_save_upload('upload', array(
        'file_validate_extensions' =&gt; array('txt'),
    ));

    //get the content in the file
    $content = file_get_contents($file-&gt;uri);

    //remove the file in temp and the pointer in the database
    file_delete($file);
}