I'm trying to create a custom element that I can use to fetch a URL instead of a file:


function mymodule_elements() {
	$type['mymodule_url'] = array(
		'#input' => true,
		'#size' => 60
		) ;
	return $type ;
}

/**
 * Theme to build the custom element
 */

function theme_mymodule_url($element) {
	$field = '<input name="%s" type="file" class="form-file" id="%s" size="%s">' ;
	return theme('form_element',$element,sprintf($field,$element['#name'],$element['#id'],$element['#size'])) ;
}

I thought the inability to get the file URL was because of the way the "file" element was written, but this doesn't return the URL either.

Am I barking up the wrong tree and if so which tree should I be barking up?

I feel like I'm going totally barking mad.

Steve

Comments

SteveTurnbull-1’s picture

Well, some information is held in $_FILES[name of field], so I can get some info I need, like this:

    $_FILES => Array
        (
            [import] => Array
                (
                    [name] => myfile.xml
                    [type] => text/xml
                    [tmp_name] => C:\wamp\tmp\php45F.tmp
                    [error] => 0
                    [size] => 353700
                )
        )

But getting the actual URL is what I really want....

Steve

SteveTurnbull-1’s picture

I'm an idiot. Of course, the nature of the web means that the server couldn't and shouldn't have the URL of a file but should get the whole file instead.

This does present issues when uploading huge files -- like audio and video -- but that's not a problem for me and there are solutions.

dman’s picture

:-)
I was gonna say how that wasn't supposed to work.. passing the full local filepath of a submitted file is regarded as unwanted behaviour when you are just uploading. You seem to have clicked about that.

I wasn't quite sure why you were using a 'file' browse input field to enter an URL... but I have seen a few OS/plugins/server-mappings where that's not totally impossible .. just a bit odd.
I think you'l be able to address whatever you are doing in some other way. I wonder if that full file path is available to browser scripts in the interval between selection and submission?

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/