我正在更改Drupal安装中的目录结构,需要删除除文件名本身之外的所有路径数据。
所以基本结构是:
+-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+
| entity_type | bundle | deleted | entity_id | revision_id | language | delta | field_filename_value | field_filename_format |
+-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+
文件名存储在field_filename_value
中。这是一个示例记录:
+-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+
| entity_type | bundle | deleted | entity_id | revision_id | language | delta | field_filename_value | field_filename_format |
+-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+
| node | presentation | 0 | 11 | 11 | und | 0 | /really long path name/with lots of words/167 Clarence Ashley - Coo Coo Bird.mp3 | NULL |
+-------------+--------------+---------+-----------+-------------+----------+-------+----------------------------------------------------------------------------------+-----------------------+
需要更改荒谬的文件名值:
/really long path name/with lots of words/167 Clarence Ashley - Coo Coo Bird.mp3
对此:
167 Clarence Ashley - Coo Coo Bird.mp3
撇开在文件/目录名称中使用空格的不良做法,你会如何纠正这个?是否可以单独使用MySQL功能?
作为一个额外的挑战,一些文件可能超过2个目录。
答案 0 :(得分:2)
使用substring_index
选择substring_index('http://www.example.com/dev/archive/examples/test.htm','/', - 1)
(以上两者均来自
如何使用它很容易,但只是解释一下,你选择/的最后一个索引,然后做另一个子串函数来切断它左边的任何东西