You are here

drupal_write_record

hong 的头像
Submitted by hong on 星期一, 2009-08-03 01:32

今天在弄drupal里面的文件上传是遇到这个问题,至今不明白,还没答案!希望有人知道这个问题!

<strong>先举个例子,来说明这个问题的大概出发点:</strong>

首先,创建一个函数:
<code>
function insert_file()
{
    //这里就是执行插入的过程!   insert date here!
 
}
</code>
当我调用这个函数时候!如下:
<code>
    insert_file(); //调用上面的函数
</code>

结果查看数据表, 居然插入了不止一条的数据! 我就开始分析原因,在上面的函数开始出加上exit()
<code>
function insert_file()
{
    exit();
    //这里就是执行插入的过程!   insert date here!
 
}
</code>
<strong>exit(); </strong> 下面的函数就不会执行,数据库里面自然也不会插入数据了。 我于是就在改上面的函数,把exit()放在
<code>
function insert_file()
{

    //这里就是执行插入的过程!   insert date here!
      exit(); //放这里
}
</code>
运行后查看数据库,刚好添加了一条数据,正合我意!  <strong>把 exit()取消就是插入多条数据!</strong>

我说的就是drupal里面的 <strong>drupal_write_record</strong>函数!
 
我先在  template.php  文件里面调用 drupal_write_record 这个函数;传递的参数我用的是

<code>
function insert_s($arg)
    {
        $dest = 'admin';
        $fil = new stdClass();
        $fil->filename = 'new'.$arg.'.jpg';
        //$file->filepath = $_FILES['files']['tmp_name'][$source];
        $fil->filepath = 'sites/default/files/'.$arg.'.jpeg';
        //$file->filemime = file_get_mimetype($file->filename);
        $fil->filemime = 'image/jpeg';
        $fil->source = $source;
        //$file->destination = file_destination(file_create_path($dest .'/'. $file->filename), $replace);
        $fil->filesize = bcadd($arg,1);
        //
        $fil->filepath = $file->destination;
        $fil->uid = 1;
        $fil->status = 1;
        $fil->timestamp = time();
       
        //echo '<pre>';
        //print_r($fil);
        drupal_write_record('files',$fil);
        //echo '</pre>';
    }

insert_s('test');
</code>

就是上面的这个数据,为什么会这样,我到现在还不知道,希望有谁遇到过!

 <strong>我这样写是为了把多张有规律的图片直接 FTP 上传到服务器,而不用手动一张一张添加图片!</strong>