- Oct 3, 2024
- 8
- 5
Hello guys today im show you how to upload your save file to the server so the user not lost her save file.
Firstly you should have a hosting service or your own VPS to do it anyway i will guide both server side & renpy code
I will choose a PHP language to hosting the save file & store him
a server side code
Now we should add a logic to our game to upload the save file lets do it
Open script.rpy
Now the save should be upload to the server
Good luck
Firstly you should have a hosting service or your own VPS to do it anyway i will guide both server side & renpy code
I will choose a PHP language to hosting the save file & store him
a server side code
PHP:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['save_file'])) {
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["save_file"]["name"]);
if (move_uploaded_file($_FILES["save_file"]["tmp_name"], $target_file)) {
echo "The file ". htmlspecialchars(basename($_FILES["save_file"]["name"])). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
Open script.rpy
Code:
define upload_url = "http://yourserver.com/upload.php"
label upload_save_file:
$ save_name = renpy.save("save_name") # Adjust the save name as necessary
$ save_path = renpy.config.save_dir + "/save_name" # Get the path to the save file
$ upload_file = renpy.file("upload_file", save_path)
python:
import requests
with open(upload_file, 'rb') as f:
files = {'save_file': f}
response = requests.post(upload_url, files=files)
renpy.say("Upload response: {}".format(response.text))
return
Good luck