PHP上传问题在wordpress,获取错误0但图像没有上传到我的文件夹

时间:2015-06-16 12:19:24

标签: php file-upload

PHP上传wordpress插件中的问题,获取错误0但图像未上传到我的文件夹。当我打印$ _FILES时,我得到了

Array
(
    [resume] => Array
        (
            [name] => ace PLACEMENTS big-.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpMOwvKP
            [error] => 0
            [size] => 155773
        )
)

我在我的wp-job manager插件中使用此代码 - > job-application-email.php文件。

html编码是:

<form action="" class="wppb-user-forms wppb-register-user" id="wppb-register-user" method="post" enctype="multipart/form-data">
        <ul>
        <li id="wppb-form-element-2" class="wppb-form-field wppb-default-username">
        <label for="name">Name<span title="This field is required" class="wppb-required">*</span></label>
        <input type="text" value="" id="name" maxlength="70" name="name" class="text-input default_field_username" required ></li>


        <li id="wppb-form-element-7" class="wppb-form-field wppb-default-website">

        <label for="phone">Phone</label>
        <input type="text" value="" id="phone" maxlength="70" name="phone" class="text-input default_field_website" required>
            <span class="wppb-description-delimiter">phone number</span></li>

        <li id="wppb-form-element-8" class="wppb-form-field wppb-default-e-mail">
        <label for="email">E-mail<span title="This field is required" class="wppb-required">*</span></label>
        <input type="email" id="email" maxlength="70" name="email" class="text-input default_field_email" placeholder="Email" required></li>

        <li id="wppb-form-element-15" class="wppb-form-field wppb-default-nickname">
        <label for="nickname">Resume</label>
        <input type="file" name="resume">
        <span class="wppb-description-delimiter">qualification</span></li></ul>
        <input type="submit" value="submit">

        </form>

php编码是:

<?php 
$tmp = $_FILES['resume']['tmp_name'];

$extension = explode(".", $_FILES['resume']['name']);
$everything = count($extension);

$ext = $extension[$everything - 1];

$newName = uniqid().time().".".$ext;
$curl = get_site_url()."/uploads";

if(move_uploaded_file($tmp, $curl."/".$newName))
{
    echo "successfully uploaded";
}
else {

echo "not uploaded";
}


?> 

2 个答案:

答案 0 :(得分:1)

这是一种自我调试方式

此错误主要有两个原因。此时,您应该自己修改以下步骤。

  1. 确保您有足够的权限上传文件夹/uploads
  2. 的图片

    注意:您可以拥有755权限

    1. 确保表格wp_options的{​​{1}}值为upload_path。 (如果没有更新)
    2. 注意:您也可以在wp-content/uploads

      更新它

答案 1 :(得分:0)

当我使用wordpress时,我从一个wordpress页面

中找到了这段代码

代码如下:

    if ( ! function_exists( 'wp_handle_upload' ) ) {
        require_once( ABSPATH . 'wp-admin/includes/file.php' );
    }

    $uploadedfile = $_FILES['resume'];

    $upload_overrides = array( 'test_form' => false );

    $movefile = wp_handle_upload( $uploadedfile, $upload_overrides );

    if ( $movefile && !isset( $movefile['error'] ) ) {
        echo "File is valid, and was successfully uploaded.\n";
        //var_dump( $movefile); 
        //If you want to see details of your uploaded file uncomment the above line
    } else {
        /**
         * Error generated by _wp_handle_upload()
         * @see _wp_handle_upload() in wp-admin/includes/file.php
         */
        echo $movefile['error'];
    }

请勿删除此“$ upload_overrides = array('test_form'=&gt; false);”从上面的代码,因为它将无法正常工作。