PHP $_FILES file loop upload

陌路散爱 提交于 2019-12-20 06:09:08

问题


I want to insert files into mysql from php function. The files that need to be uploaded are already present on the server, so I don't want to use the upload form.

I want to loop through the directory and get the files info into $_FILES.

Please let me know how I will get the $file into $_FILES and then call upload.

$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {
  echo "$file";
}

回答1:


$_FILES is solely for handling files uploaded to the script by the client. You should be able to insert the file contents using file_get_contents() or fopen()/fread() without further ado.




回答2:


If the files are already on the server then they don't need to be "uploaded". They just need to be moved.

You could try something like...

$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {
    // example query may be...
    $sql = sprintf("INSERT INTO table SET filename = %s", mysql_escape_string($path . "/" . $file));
    mysql_query($sql);
}


来源:https://stackoverflow.com/questions/1796628/php-files-file-loop-upload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!