Add image attachements
rodzic
3006e1f284
commit
206c46514a
50
index.php
50
index.php
|
@ -7,7 +7,8 @@
|
||||||
* For educational purposes only.
|
* For educational purposes only.
|
||||||
* The Server produces an Actor who can be followed.
|
* The Server produces an Actor who can be followed.
|
||||||
* The Actor can send messages to followers.
|
* The Actor can send messages to followers.
|
||||||
* Those messages can have linkable URls, hashtags, and mentions.
|
* The message can have linkable URls, hashtags, and mentions.
|
||||||
|
* An image and alt text can be attached to the message.
|
||||||
* The Server saves logs about requests it receives and sends.
|
* The Server saves logs about requests it receives and sends.
|
||||||
* This code is NOT suitable for production use.
|
* This code is NOT suitable for production use.
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
@ -381,6 +382,10 @@ echo <<< HTML
|
||||||
<form action="/send" method="post" enctype="multipart/form-data">
|
<form action="/send" method="post" enctype="multipart/form-data">
|
||||||
<label for="content">Your message:</label><br>
|
<label for="content">Your message:</label><br>
|
||||||
<textarea id="content" name="content" rows="5" cols="32"></textarea><br>
|
<textarea id="content" name="content" rows="5" cols="32"></textarea><br>
|
||||||
|
<label for="image">Attach an image</label><br>
|
||||||
|
<input type="file" name="image" id="image" accept="image/*"><br>
|
||||||
|
<label for="alt">Alt Text</label>
|
||||||
|
<input type="text" name="alt" id="alt" size="32" /><br>
|
||||||
<label for="password">Password</label><br>
|
<label for="password">Password</label><br>
|
||||||
<input type="password" name="password" id="password" size="32"><br>
|
<input type="password" name="password" id="password" size="32"><br>
|
||||||
<input type="submit" value="Post Message">
|
<input type="submit" value="Post Message">
|
||||||
|
@ -406,6 +411,46 @@ HTML;
|
||||||
// Process the content into HTML to get hashtags etc
|
// Process the content into HTML to get hashtags etc
|
||||||
list( "HTML" => $content, "TagArray" => $tags ) = process_content( $content );
|
list( "HTML" => $content, "TagArray" => $tags ) = process_content( $content );
|
||||||
|
|
||||||
|
// Is there an image attached?
|
||||||
|
if ( isset( $_FILES['image']['tmp_name'] ) && ("" != $_FILES['image']['tmp_name'] ) ) {
|
||||||
|
// Get information about the image
|
||||||
|
$image = $_FILES['image']['tmp_name'];
|
||||||
|
$image_info = getimagesize( $image );
|
||||||
|
$image_ext = image_type_to_extension( $image_info[2] );
|
||||||
|
$image_mime = $image_info["mime"];
|
||||||
|
|
||||||
|
// Files are stored according to their hash
|
||||||
|
// A hash of "abc123" is stored in "/images/abc123.jpg"
|
||||||
|
$sha1 = sha1_file( $image );
|
||||||
|
$image_path = "images";
|
||||||
|
$image_full_path = "{$image_path}/{$sha1}.{$image_ext}";
|
||||||
|
|
||||||
|
// Move media to the correct location
|
||||||
|
// Create a directory if it doesn't exist
|
||||||
|
if( ! is_dir( $image_path ) ) {
|
||||||
|
mkdir( $image_path );
|
||||||
|
}
|
||||||
|
move_uploaded_file($image, $image_full_path );
|
||||||
|
|
||||||
|
// Get the alt text
|
||||||
|
if ( isset( $_POST["alt"] ) ) {
|
||||||
|
$alt = $_POST["alt"];
|
||||||
|
} else {
|
||||||
|
$alt = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct the attachment value for the post
|
||||||
|
$attachment = [
|
||||||
|
"type" => "Image",
|
||||||
|
"mediaType" => "{$image_mime}",
|
||||||
|
"url" => "https://{$server}/{$image_full_path}",
|
||||||
|
"name" => $alt
|
||||||
|
];
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$attachment = [];
|
||||||
|
}
|
||||||
|
|
||||||
// Current time - ISO8601
|
// Current time - ISO8601
|
||||||
$timestamp = date( "c" );
|
$timestamp = date( "c" );
|
||||||
|
|
||||||
|
@ -426,7 +471,8 @@ HTML;
|
||||||
"content" => $content,
|
"content" => $content,
|
||||||
"contentMap" => ["en" => $content],
|
"contentMap" => ["en" => $content],
|
||||||
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
||||||
"tag" => $tags
|
"tag" => $tags,
|
||||||
|
"attachment" => $attachment
|
||||||
];
|
];
|
||||||
|
|
||||||
// Construct the Message
|
// Construct the Message
|
||||||
|
|
Ładowanie…
Reference in New Issue