Browse Source

Remove existing files before uploading to allow replacement

Zachary Kotlarek 9 years ago
parent
commit
65ffbe5fa4
2 changed files with 26 additions and 0 deletions
  1. 20 0
      opendrive.php
  2. 6 0
      upload.php

+ 20 - 0
opendrive.php

@@ -272,6 +272,26 @@ function rmFolder($session, $path) {
 	return false;
 }
 
+# Delete a file
+function rmFile($session, $path) {
+	$id = fileID($session, $path);
+	if ($id) {
+		return false;
+	}
+
+	$data = array(
+		'session_id'	=> $session,
+		'folder_id'	=> $id
+	);
+	$response = curlPost('/file/trash.json', $data);
+
+	# Check the result
+	if ($response['DirUpdateTime']) {
+		return true;
+	}
+	return false;
+}
+
 # Return the ID of a file
 function fileID($session, $path) {
 	$data = array(

+ 6 - 0
upload.php

@@ -98,6 +98,12 @@ while ($row = $files->fetch()) {
 		continue;
 	}
 
+	# Delete the file if it already exists
+	if (fileID($session, $row['path'])) {
+		echo 'Replacing file: ' . $row['path'] . "\n";
+		rmFile($session, $row['path']);
+	}
+
 	# Upload the file
 	if ($DEBUG) {
 		echo 'Uploading file (' . $stat['size'] . ' bytes): ' . $row['path'] . "\n";