admin管理员组文章数量:1122846
i am trying to upload image it is uploaded successfully but when i tried to access it in phpmysql the link is somethig like this : http://localhost/job/?attachment_id=40
i want to store this image url like this: http://localhost/job/wp-content/uploads/2015/05/Koala.jpg
here is code to upload image:
if(!empty($_FILES['photo_rcb'])) {
$file = $_FILES['photo_rcb'];
$upload = wp_handle_upload($file, array('test_form' => false));
// print_r($upload);exit;
if(!isset($upload['error']) && isset($upload['file'])) {
$filetype = wp_check_filetype(basename($upload['file']), null);
$title = $file['name'];
$ext = strrchr($title, '.');
$title = ($ext !== false) ? substr($title, 0, -strlen($ext)) : $title;
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => addslashes($title),
'post_content' => '',
'post_status' => 'inherit',
'post_author' => $user_id
);
$attach_key = 'document_file_id';
$attach_id = wp_insert_attachment($attachment, $upload['file']);
update_user_meta($user_id,'photo_rcb', $attach_id);
}
i am trying to upload image it is uploaded successfully but when i tried to access it in phpmysql the link is somethig like this : http://localhost/job/?attachment_id=40
i want to store this image url like this: http://localhost/job/wp-content/uploads/2015/05/Koala.jpg
here is code to upload image:
if(!empty($_FILES['photo_rcb'])) {
$file = $_FILES['photo_rcb'];
$upload = wp_handle_upload($file, array('test_form' => false));
// print_r($upload);exit;
if(!isset($upload['error']) && isset($upload['file'])) {
$filetype = wp_check_filetype(basename($upload['file']), null);
$title = $file['name'];
$ext = strrchr($title, '.');
$title = ($ext !== false) ? substr($title, 0, -strlen($ext)) : $title;
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => addslashes($title),
'post_content' => '',
'post_status' => 'inherit',
'post_author' => $user_id
);
$attach_key = 'document_file_id';
$attach_id = wp_insert_attachment($attachment, $upload['file']);
update_user_meta($user_id,'photo_rcb', $attach_id);
}
Share
Improve this question
asked May 21, 2015 at 4:30
Dhiraj PatelDhiraj Patel
1
1
- What are you trying to do exactly? Retrieve the URL? – Syed Priom Commented May 21, 2015 at 4:58
3 Answers
Reset to default 0Images should upload in that format when using wp_handle_upload. It is unclear exactly how you are getting http://localhost/job/?attachment_id=40
I would suggest having something similar to the Handling the File Upload section of this post:
- How can I add an image upload field directly to a custom write panel?
One of the greatest problems with WordPress is the picture upload issue, which has neither a clear cause nor a clear fix. This picture upload difficulty is caused by several factors, and various fixes are available. Actually, it's hard to forecast when anything will happen, and it occasionally happens at random. is that image uploaded error occurring with all types of images? If every image you have has an uploading problem:
- alter the file's permissions.
- Plugins should be disabled, especially those that enhance photos.
- Increase the WordPress and PHP memory limitations for your website.
- On the Media Settings screen, delete the file path.
- See if your PHP version is the source of the problem. you can try several types of solutions for uploading images without any error in WordPress. I would suggest some ways to fix your error with image uploading. So try this "Fix the Image Upload Issue in WordPress" and fix your problem and get free from that issue.
There might be some plugin conflict causing this. Please try deactivating and activating plugins one by one. If that does not fix it then try to update the WP version to the latest; if not done yet.
Try to see in the console if there is any error generated or not.
本文标签: pluginsimage upload error wordpress
版权声明:本文标题:plugins - image upload error wordpress 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310367a1934350.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论