将文件路径存储在数据库中 [英] Store filepaths in a Database

查看:232
本文介绍了将文件路径存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在'/ music / single /'中有一个名为'run.mp3'的文件,我需要填写表格:

  id艺术家文件名文件路径

ai single run / music /single/run.mp3

我已经在Google上搜索了任何解释,到PHP和MySQL我真的需要援助在这里。

我已经试过:

  $ files = scandir(../ music /); 
$ b foreach($ files as $ file){
$ paths = explode(/,$ file);

$ artist = $ paths [1];
$ song = $ paths [2];

if(mysqli_connect_errno()){
echo无法连接到MySQL:。 mysqli_connect_error();

$ b $ mysqli_query($ con,INSERT INTO playlist(artist,song,filepath)VALUES('$ artist','$ song','$ file');

mysqli_close($ con);

编辑输出 $ print $($ files);

  Array([0] =>。[1 ...] [2] => C418-Alpha [3] => C418-Beta),
Array([0] => [1] => .. [2] C418-Beta),
Array([0] => [1] => .. [2] => C418-Alpha [3] = [C418-Beta],
Array([0] =>。[1] => .. [2] => C418-Alpha [3] => C418-Beta) $ b


解决方案

可能是这个文档可以帮助你获得使用PHP的路径。



一旦你有了路径,你可以执行一个 mysqli_query 命令来插入到数据库中

这里可以找到一个有用的例子...


Im trying to get filepaths and filenames in a sql database.

i have a file called 'run.mp3' in '/music/single/' for this i would need to fill a table with:

id artist filename filepath

ai single run      /music/single/run.mp3

I've searched google for any explanation on this and since im rather new to php and mysql I really need assistance here.

What I have tried:

$files = scandir(../music/); 

foreach($files as $file) {
    $paths  = explode("/", $file);

    $artist = $paths[1];
    $song = $paths[2];

if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

mysqli_query($con,"INSERT INTO playlist (artist, song,filepath) VALUES ('$artist', '$song', '$file')";

mysqli_close($con);

EDIT output of $print_r($files);:

Array ( [0] => . [1] => .. [2] => C418 - Alpha [3] => C418 - Beta ),
Array ( [0] => . [1] => .. [2] => C418 - Alpha [3] => C418 - Beta ),
Array ( [0] => . [1] => .. [2] => C418 - Alpha [3] => C418 - Beta ),
Array ( [0] => . [1] => .. [2] => C418 - Alpha [3] => C418 - Beta )

解决方案

May be this documentation could help you getting the path using PHP.

And once you have the path you could execute a mysqli_query command to make the insertion into the DB

Here you can find an useful example...

这篇关于将文件路径存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆