PHP $_FILES file loop upload

后端 未结 2 1980
走了就别回头了
走了就别回头了 2021-01-29 05:27

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 wan

相关标签:
2条回答
  • 2021-01-29 05:57

    $_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.

    0 讨论(0)
  • 2021-01-29 06:16

    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);
    }
    
    0 讨论(0)
提交回复
热议问题