URL duplication issue WordPress

I have an issue in the download link, the URL getting duplicate. Like this http://localhost/test/files/http://localhost/test/files/2016/05/testonly.docx

same as the live website: http://www.homecredit.ph/wp-content/uploads/home1/homecre1/public_html/files/News-26.jpg, the URL messed up

Read More

How to fix this? I didn’t add anything in the .htaccess

.htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php [L]
</IfModule>

# END WordPress

Here’s the code for download link:

functions.php

function upload_user_file($file = array()){
    require_once(ABSPATH . 'wp-admin/includes/admin.php');
      $file_return = wp_handle_upload($file, array('test_form' => false));
      if(isset($file_return['error']) || isset($file_return['upload_error_handler'])){
          return false;
      } else {
          $filename = $file_return['file'];
          $attachment = array(
              'post_mime_type' => $file_return['type'],
              'post_title' => preg_replace('/.[^.]+$/', '', basename($filename)),
              'post_content' => '',
              'post_status' => 'inherit',
              'guid' => $file_return['url']
          );

          $attachment_id = wp_insert_attachment($attachment, $file_return['url']);

          require_once(ABSPATH . 'wp-admin/includes/file.php');
          $attachment_data = wp_generate_attachment_metadata($attachment_id, $filename);
          wp_update_attachment_metadata($attachment_id, $attachment_data);

          if(0 < intval($attachment_id)){
            return $attachment_id;
          }
      }
      return false;
}

Custom page template

echo '<td id="resumeFile'.$optionId.'"><a href=' . wp_upload_dir($record_s->attachment_resume_id) . '>Download Resume</a></td>';

Related posts

Leave a Reply