wordPress 如何儲存外掛程式中上傳的圖片到對應外掛程式的目錄下面?

來源:互聯網
上載者:User
關鍵字 php wordpress
開發了個外掛程式中有個上傳圖片的功能,外掛程式下面有個目錄是img儲存圖片的,想問如何課一儲存上傳的啊圖片到這個目錄?

// Check that the nonce is valid, and the user can edit this post.if (    isset($_POST['my_image_upload_nonce'], $_POST['post_id'])    && wp_verify_nonce($_POST['my_image_upload_nonce'], 'my_image_upload')    && current_user_can('edit_post', $_POST['post_id'])) {    // The nonce was valid and the user has the capabilities, it is safe to continue.    // These files need to be included as dependencies when on the front end.    require_once(ABSPATH . 'wp-admin/includes/image.php');    require_once(ABSPATH . 'wp-admin/includes/file.php');    require_once(ABSPATH . 'wp-admin/includes/media.php');    // Let WordPress handle the upload.    // Remember, 'my_image_upload' is the name of our file input in our form above.    $url=WPWSL_PLUGIN_URL . '/img/' . $imageSize . '.png';//    update_option('upload_path',WP_CONTENT_DIR.'/uploads');    update_option('upload_path',WPWSL_PLUGIN_URL.'/img/');    $attachment_id = media_handle_upload('my_image_upload', $_POST['post_id']);    if (is_wp_error($attachment_id)) {        // There was an error uploading the image.        echo "

There was an error uploading your file.

"; } else { // The image was uploaded successfully! echo "

The image was uploaded successfully!

"; add_filter('img', $attachment_id);// add_filter('img', 'custom_upload_directory'); }} else { echo "

The security check failed, maybe show the user an error

"; // The security check failed, maybe show the user an error.}
  1. 清單項目

                                                                                 

回複內容:

開發了個外掛程式中有個上傳圖片的功能,外掛程式下面有個目錄是img儲存圖片的,想問如何課一儲存上傳的啊圖片到這個目錄?

// Check that the nonce is valid, and the user can edit this post.if (    isset($_POST['my_image_upload_nonce'], $_POST['post_id'])    && wp_verify_nonce($_POST['my_image_upload_nonce'], 'my_image_upload')    && current_user_can('edit_post', $_POST['post_id'])) {    // The nonce was valid and the user has the capabilities, it is safe to continue.    // These files need to be included as dependencies when on the front end.    require_once(ABSPATH . 'wp-admin/includes/image.php');    require_once(ABSPATH . 'wp-admin/includes/file.php');    require_once(ABSPATH . 'wp-admin/includes/media.php');    // Let WordPress handle the upload.    // Remember, 'my_image_upload' is the name of our file input in our form above.    $url=WPWSL_PLUGIN_URL . '/img/' . $imageSize . '.png';//    update_option('upload_path',WP_CONTENT_DIR.'/uploads');    update_option('upload_path',WPWSL_PLUGIN_URL.'/img/');    $attachment_id = media_handle_upload('my_image_upload', $_POST['post_id']);    if (is_wp_error($attachment_id)) {        // There was an error uploading the image.        echo "

There was an error uploading your file.

"; } else { // The image was uploaded successfully! echo "

The image was uploaded successfully!

"; add_filter('img', $attachment_id);// add_filter('img', 'custom_upload_directory'); }} else { echo "

The security check failed, maybe show the user an error

"; // The security check failed, maybe show the user an error.}
  1. 清單項目

                                                                                 
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.