admin管理员组文章数量:1122826
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: .jpg, the URL messed up
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>';
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
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>';
Share
Improve this question
edited May 20, 2016 at 5:41
User014019
asked May 20, 2016 at 1:35
User014019User014019
1533 silver badges13 bronze badges
1
- The issue might not be related to .htacess file. It might be in how you generated the link. Could you provide the code to the download link so that we might know what's going on – bagpipper Commented May 20, 2016 at 3:44
1 Answer
Reset to default 0I just examined your URL http://www.homecredit.ph/wp-content/uploads/home1/homecre1/public_html/files/News-26.jpg and code and noticed that, you are saving your image in http://www.homecredit.ph/files/News-26.jpg path but trying to access from upload directory of WordPress. /home1/homecre1/public_html/files/News-26.jpg - this is the path stored in database for your attachment ID. /home1/homecre1/public_html/ - This is your root directory where WordPress installed. So better save only the file name in db or remove the root path from the database value and attach with site url. EG:
$filePath = str_replace('/home1/homecre1/public_html', '', $record_s->attachment_resume_id);
echo '<td id="resumeFile'.$optionId.'"><a href=' . $filePath . '>Download Resume</a></td>';
It's just an example. You should not hard code the path in str_replace function. You need to use PHP function to get the root path and place it in the function. First try with the above code. If it works then proceed with the above step.
本文标签: url rewritingHow to remove Base URL Duplication
版权声明:本文标题:url rewriting - How to remove Base URL Duplication? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736284936a1927354.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论