@chervonfunky

Загрузка файла на сервер через contact form wordpress, реально ли?

В популярном плагине contact form для wordpress столкнулся с одной задачей:

Как сделать что бы прикрепленные файлы загружались на сервер сайта в определенную папку и при этом ссылка на скачивание приходила в email сообщении?

По умолчанию форма размещает файл во временную папку и отправляет заявку, далее очищает временную папку.

Вообщем необходимо что бы файл приходил с ссылкой на скачивание, а не прикреплялся к письму т.к. файлы будут иметь размеры до 2 GB

Заранее благодарен за помощь!

Как отменить стирания файлов из кеша?

/* File uploading functions */

function wpcf7_init_uploads() {
$dir = wpcf7_upload_tmp_dir();
wp_mkdir_p( $dir );

$htaccess_file = trailingslashit( $dir ) . '.htaccess';

if ( file_exists( $htaccess_file ) ) {
return;
}

if ( $handle = @fopen( $htaccess_file, 'w' ) ) {
fwrite( $handle, "Deny from all\n" );
fclose( $handle );
}
}

function wpcf7_maybe_add_random_dir( $dir ) {
do {
$rand_max = mt_getrandmax();
$rand = zeroise( mt_rand( 0, $rand_max ), strlen( $rand_max ) );
$dir_new = path_join( $dir, $rand );
} while ( file_exists( $dir_new ) );

if ( wp_mkdir_p( $dir_new ) ) {
return $dir_new;
}

return $dir;
}

function wpcf7_upload_tmp_dir() {
if ( defined( 'WPCF7_UPLOADS_TMP_DIR' ) )
return WPCF7_UPLOADS_TMP_DIR;
else
return wpcf7_upload_dir( 'dir' ) . '/wpcf7_uploads';
}

add_action( 'template_redirect', 'wpcf7_cleanup_upload_files', 20 );

function wpcf7_cleanup_upload_files( $seconds = 60, $max = 100 ) {
if ( is_admin() || 'GET' != $_SERVER['REQUEST_METHOD']
|| is_robots() || is_feed() || is_trackback() ) {
return;
}

$dir = trailingslashit( wpcf7_upload_tmp_dir() );

if ( ! is_dir( $dir ) || ! is_readable( $dir ) || ! wp_is_writable( $dir ) ) {
return;
}

$seconds = absint( $seconds );
$max = absint( $max );
$count = 0;

if ( $handle = @opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
if ( $file == "." || $file == ".." || $file == ".htaccess" ) {
continue;
}

$mtime = @filemtime( $dir . $file );

if ( $mtime && time() < $mtime + $seconds ) { // less than $seconds old
continue;
}

wpcf7_rmdir_p( path_join( $dir, $file ) );
$count += 1;

if ( $max <= $count ) {
break;
}
}

closedir( $handle );
}
}
  • Вопрос задан
  • 843 просмотра
Пригласить эксперта
Ответы на вопрос 1
smidl
@smidl
WordPress-разработчик
Looking at submit() in WPCF7_Submission we see a call to remove_uploaded_files() which has no filter to stop it. So apparently what you are trying to do isn't meant to be done by the author of CF7.

So apart from getting the author to include a hook there the only way I see is that you generate your file and then create a copy before adding it to the form submission so your original file stays.


Короче, через правку кода плагина)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы