Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms 在drupal 7中获取上载文件的路径_Forms_File_Path_Get_Drupal 7 - Fatal编程技术网

Forms 在drupal 7中获取上载文件的路径

Forms 在drupal 7中获取上载文件的路径,forms,file,path,get,drupal-7,Forms,File,Path,Get,Drupal 7,我现在正在使用drupal 7,这是一个从桌面上传照片的表单: $form['Background image'] = array( '#type' => 'file', '#title' => t('Image'), '#page arguments' => array('testform'), '#access callback' => TRUE, '#description' => t('Click "Br

我现在正在使用drupal 7,这是一个从桌面上传照片的表单:

     $form['Background image'] = array(
    '#type' => 'file', 
    '#title' => t('Image'), 
    '#page arguments' => array('testform'),
    '#access callback' => TRUE,
    '#description' => t('Click "Browse..." to select an image to upload.'),
    //Get the file path

    );

我的问题是如何获取所选照片的路径,以便我以后可以创建一个对象(使用照片的路径)保存在数据库中?

在提交处理程序中,您将可以访问提交的文件属性

您可以这样做以获取文件url:

使用以下命令加载文件对象:

$files_obj = file_load($form_state['values']['Background image']);
获取url:

$url = file_create_url($files_obj->uri);