Hello everyone,
Newbie question and first post to the local group!
For reasons I can't quite understand, I'm trying to teach myself a little Drupal module development. Apparently just setting things up and keeping them running isn't enough. Anyhow, I've built a little module that takes bits of information, artist name, title of work, etc, and lets you select a cover file. The whole thing gets passed to an external script which is already working (Linux command line I can deal with).
What I want to do, which I can't wrap my head around, is a way to extract just the image_file name from what gets selected.
$form['image_file'] = array( '#type' => 'media', '#title' => t('Select Artwork:'), '#description' => t('The media selector will let you choose from a selection of cover art available on this system. Just click the Select media button below and find something you like.'), );
The image itself gets stored in
~/www/sites/default/files/blue_cover.png
and for the sake of my script, I want just the "blue_cover" part of that returned to a variable in my subroutine.
That's where I'm stuck. How do I return the file name, all by its lonesome? I've tried several variations but nothing works out quite right.
Ideas? Suggestions?
--
Marcel Gagné
Note: This massagee wos nat speel or gramer-checkered.
Comments
pathinfo
Hi, when I needed to extract bits and pieces from a file path before I use the pathinfo function.
http://php.net/manual/en/function.pathinfo.php
php > $fileinfo = pathinfo('~/www/sites/default/files/blue_cover.png');
php > var_dump($fileinfo);
array(4) {
["dirname"]=>
string(25) "~/www/sites/default/files"
["basename"]=>
string(14) "blue_cover.png"
["extension"]=>
string(3) "png"
["filename"]=>
string(10) "blue_cover"
}
For this, check the API
For this, check the Drupal API. It is your friend.
You can find it here: http://api.drupal.org/api/drupal
Specifically, what you want will depend on how your images are implemented.
It will be either:
http://api.drupal.org/api/drupal/includes!file.inc/group/file/7
Or the more complex:
http://api.drupal.org/api/drupal/modules!field!field.module/group/field/7
Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.