I'm trying to upload a external image to my Wordpress database with a PHPcode
This the code I try to use for it:
<?php
include ("../wordpress/wp-includes/post.php");
include ("../wordpress/wp-includes/functions.php");
include ("../wordpress/wp-admin/includes/image.php");
// $filename should be the path to a file in the upload directory.
$filename = '../wordpress/wp-content/uploads/2016/02/220px-Smiley.svg.png';
// The ID of the post this attachment is for.
$parent_post_id = 22;
// Check the type of file. We'll use this as the 'post_mime_type'.
$filetype = wp_check_filetype( basename( $filename ), null );
// Get the path to the upload directory.
$wp_upload_dir = wp_upload_dir();
// Prepare an array of post data for the attachment.
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
'post_mime_type' => $filetype['type'],
'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
'post_content' => '',
'post_status' => 'inherit'
);
// Insert the attachment.
$attach_id = wp_insert_attachment( $attachment, $filename, $parent_post_id );
// Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
require_once( ABSPATH . '../wordpress/wp-admin/includes/image.php' );
// Generate the metadata for the attachment, and update the database record.
$attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
wp_update_attachment_metadata( $attach_id, $attach_data );
set_post_thumbnail( $parent_post_id, $attach_id );
but when I try to run it I have this error code:
Warning: require(ABSPATHWPINC/option.php): failed to open stream: No such file or directory in /home/sales/domains/lilopel.com/public_html/wouter/wordpress/wp-includes/functions.php on line 8
Warning: require(ABSPATHWPINC/option.php): failed to open stream: No such file or directory in /home/sales/domains/lilopel.com/public_html/wouter/wordpress/wp-includes/functions.php on line 8
Fatal error: require(): Failed opening required 'ABSPATHWPINC/option.php' (include_path='.:/usr/local/lib/php') in /home/sales/domains/lilopel.com/public_html/wouter/wordpress/wp-includes/functions.php on line 8
Does anyone have an idea how to fix this error?