为什么$ _FILES ['uploadfiles']无法运行并且运行空白?

时间:2015-06-18 11:33:23

标签: wordpress file-upload amazon-ec2 bitnami wordpress-thesis-theme

我正在尝试在打印

时通过wordpress中的custom.php上传图像
`$_FILES['uploadfiles'];` 

它没有显示我在前一天在另一个wordpress网站上使用的相同代码的代码在ec2上我的当前wordpress在ec2并且有bitnami图像我已经检查了所有配置在php.ini档案upload_tmp_dir=/opt/bitnami/php/tmpfile_uploads=onupload_max_filesize=40M

我没有使用任何表格我只是在一个钩子中添加了上传字段,在一个页面上显示该字段。

我正在使用论文主题。所以今天任何人都知道为什么这个代码发生了同时代码的一个副本在另一个带有大师主题的wordpress上工作。

Bellow是我用来上传图片的代码。

<input type="file" name="uploadfiles[]" id="uploadfiles" size="35" class="uploadfiles" />



<?php
$uploadfiles = $_FILES['uploadfiles'];

print_r ($uploadfiles);

  if (is_array($uploadfiles)) {
  echo "1";
    foreach ($uploadfiles['name'] as $key => $value) {

      // look only for uploded files
      if ($uploadfiles['error'][$key] == 0) {

        $filetmp = $uploadfiles['tmp_name'][$key];

        //clean filename and extract extension
        $filename = $uploadfiles['name'][$key];

        // get file info
        // @fixme: wp checks the file extension....
        $filetype = wp_check_filetype( basename( $filename ), null );
        $filetitle = preg_replace('/\.[^.]+$/', '', basename( $filename ) );
        $filename = $filetitle . '.' . $filetype['ext'];
        $upload_dir = wp_upload_dir();

        /**
         * Check if the filename already exist in the directory and rename the
         * file if necessary
         */
        $i = 0;
        while ( file_exists( $upload_dir['path'] .'/' . $filename ) ) {
          $filename = $filetitle . '_' . $i . '.' . $filetype['ext'];
          $i++;
        }
        $filedest = $upload_dir['path'] . '/' . $filename;


        /**
         * Check write permissions
         */
        if ( !is_writeable( $upload_dir['path'] ) ) {
          $this->msg_e('Unable to write to directory %s. Is this directory writable by the server?');
          return;
        }

        /**
         * Save temporary file to uploads dir
         */
        if ( !@move_uploaded_file($filetmp, $filedest) ){
          $this->msg_e("Error, the file $filetmp could not moved to : $filedest ");
          continue;
        }

        $attachment = array(
          'post_mime_type' => $filetype['type'],
          'post_title' => $filetitle,
          'post_content' => '',
          'post_status' => 'inherit'
        );

        $attach_id = wp_insert_attachment( $attachment, $filedest );
        require_once( ABSPATH . "wp-admin" . '/includes/image.php' );
        $attach_data = wp_generate_attachment_metadata( $attach_id, $filedest );
        echo $attach_data; 

        echo $filedest; 


        wp_update_attachment_metadata( $attach_id,  $attach_data );
        //echo wp_get_attachment_url( $attach_id );
        //exit();
        $urlimage=wp_get_attachment_url( $attach_id );
          $_SESSION["oldurl"]=$urlimage; 
        echo  $_SESSION["oldurl"];
      }
    }
  }
   ?>

0 个答案:

没有答案