How can PHP be used to select files on network drives and save their complete network paths in a database?
To select files on network drives and save their complete network paths in a database using PHP, you can use the PHP `scandir()` function to scan the directory on the network drive, retrieve the file paths, and then save them to a database using SQL queries. Make sure that the PHP script has the necessary permissions to access the network drive and write to the database.
// Specify the network drive path
$network_drive_path = '//server/share/';
// Get the list of files in the network drive directory
$files = scandir($network_drive_path);
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
$conn = new mysqli($servername, $username, $password, $dbname);
// Save the file paths to the database
foreach($files as $file) {
$filepath = $network_drive_path . $file;
$sql = "INSERT INTO files (filepath) VALUES ('$filepath')";
$conn->query($sql);
}
// Close the database connection
$conn->close();