scratch
/file.php |
@@ -85,6 +85,48 @@ |
|
#### Store the file. |
$timestamp = atomized_put_contents($userPath.'.'.$fileExtension, $data); |
|
### Process any sent tags. |
if(isset($_POST['tags'])) { |
$tags = json_decode( |
stripslashes( |
$_POST['tags'] |
) |
); |
|
## If we have any tags then insert them into the database. |
if(!empty($tags)) { |
try { |
## Connect or create the scratch database. |
$db = new PDO('sqlite:db/scratch.sqlite3'); |
## Set the error mode to exceptions. |
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
## Begin the transaction |
$db->beginTransaction(); |
|
## Create the tags table if it does not exist. |
$db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE)'); |
|
## Insert all the tags for the file. |
foreach($tags as $tag) { |
$q = $db->prepare("INSERT INTO tags(hash, tag) VALUES(:hash, :tag)"); |
$q->execute( |
array( |
':hash' => $file, |
':name' => $tag |
) |
); |
} |
|
## Commit the transaction. |
$db->commit(); |
} catch (Exception $e) { |
## Rollback. |
$db->rollback(); |
} |
} |
} |
|
### Hook for various file extensions. |
$opengraph = FALSE; |
@@ -94,7 +136,7 @@ |
$opengraph = TRUE; |
break; |
} |
|
|
### Return the URL to the file. |
header('Content-Type: text/plain; charset=utf-8'); |
echo json_encode( |