• Resolved jeboor

    (@jeboor)


    Hi!

    I am currently developing a website for local school. I installed the existing WordPress website on a local machine runnning a local webserver via XAMPP. I created a custom post type with custom meta boxes for uploading pdf documents. In one of the boxes, the admin uploads the actual document. I’ve inserted a control which checks if the file input is empty. If it is, a wp_die() is triggered to let the admin know of the mistake. However, as I try to test if the error message is displayed, I am instead of the message getting a “Access Denied” page. The page doesn’t contain any other information, so trying to locate the error in the code isn’t possible.

    I am able to upload documents and data to the content folder and database.

    if(!empty($_FILES['wp_pdf_attachment']['name'])) {
        // Store supported file types (ONLY PDF!)
        $supported_file_types = array('application/pdf');
        // Get the file type to upload
        $array_file_type = wp_check_filetype(basename(
          $_FILES['wp_pdf_attachment']['name']));
        $upload_file_type = $array_file_type['type'];
        // Check if upload file type is supported
        if(in_array($upload_file_type, $supported_file_types)) {
          // Upload file, using WordPress API
          $upload = wp_upload_bits($_FILES['wp_pdf_attachment']['name'],
            null, file_get_contents($_FILES['wp_pdf_attachment']['tmp_name']));
          if(isset($upload['error']) && $upload['error'] != 0) {
            wp_die('Det uppstod ett fel under uppladdningen: ' . $upload['error']);
          } else {
            add_post_meta($post_id, 'wp_pdf_attachment', $upload);
            update_post_meta($post_id, 'wp_pdf_attachment', $upload);
          }
    
        } else {
          wp_die('Filtypen f?r uppladdningen ?r inte PDF');
        }
      } else {
        wp_die('Ingen fil lades till f?r uppladdning');
      }

    I tried stepping trough the code to see if the error occured because of my code. The code ran all the way until the last else statement and then continued into the wp_die() functions inside wp-includes/functions.php.

    Any idea what the problem might be? Are there any steps I can take to find the problem? Could it be because I am running version 3.9.11? I’ve read online that you shouldn’t update as the first attempt at solving a problem.

    Thanks beforehand!

Viewing 1 replies (of 1 total)
  • Thread Starter jeboor

    (@jeboor)

    Found the solution. Apparently another installed plugin I didn’t know of was interfering. Uninstalled it and now everything works as it should.

Viewing 1 replies (of 1 total)
  • The topic ‘Access denied when calling wp_die()’ is closed to new replies.