fix name save file

This commit is contained in:
haakel 2024-06-24 16:56:26 +03:30
parent b9ed728e86
commit 43bb2ab021
1 changed files with 5 additions and 16 deletions

View File

@ -48,14 +48,6 @@ class Audio_Diary_Admin_Page {
} }
} }
function handle_download_zip() { function handle_download_zip() {
if (!current_user_can('manage_options')) { if (!current_user_can('manage_options')) {
wp_send_json_error(['message' => 'Unauthorized']); wp_send_json_error(['message' => 'Unauthorized']);
@ -195,6 +187,7 @@ class Audio_Diary_Admin_Page {
wp_mkdir_p($audio_dir); wp_mkdir_p($audio_dir);
} }
} }
public function save_audio() { public function save_audio() {
if (!current_user_can('manage_options')) { if (!current_user_can('manage_options')) {
wp_send_json_error('Unauthorized'); wp_send_json_error('Unauthorized');
@ -210,22 +203,18 @@ public function save_audio() {
$uploads = wp_upload_dir(); $uploads = wp_upload_dir();
$upload_path = $uploads['basedir'] . '/audio-diary/'; $upload_path = $uploads['basedir'] . '/audio-diary/';
// Check if the directory exists, if not create it $date_time = date('Y-m-d H-i-s');
if (!file_exists($upload_path)) { $file_name = 'memory-' . $date_time . '.wav';
wp_mkdir_p($upload_path);
}
$file_name = 'audio-' . time() . '.wav';
$file_path = $upload_path . $file_name; $file_path = $upload_path . $file_name;
// Move the uploaded file to the audio-diary directory
if (move_uploaded_file($file['tmp_name'], $file_path)) { if (move_uploaded_file($file['tmp_name'], $file_path)) {
wp_send_json_success('File uploaded'); wp_send_json_success(['message' => 'File uploaded', 'file_name' => $file_name]);
} else { } else {
wp_send_json_error('File upload failed'); wp_send_json_error('File upload failed');
} }
} }
} }
Audio_Diary_Admin_Page::get_instance(); Audio_Diary_Admin_Page::get_instance();