Reputation: 6755
PHP Uploading issue in wordpress plugin, Getting Error 0 but the image was not uploaded to my folder. When I print out $_FILES I get
Array
(
[resume] => Array
(
[name] => ace PLACEMENTS big-.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpMOwvKP
[error] => 0
[size] => 155773
)
)
I'm using this code in my wp-job manager plugin -> job-application-email.php file.
html coding is:
<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 coding is:
<?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";
}
?>
Upvotes: 1
Views: 422
Reputation: 6755
As I am using wordpress, I found this code from one of a wordpress page
the code is as follows:
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'];
}
do not remove this "$upload_overrides = array( 'test_form' => false );" from above code, as it will not work.
Upvotes: 0
Reputation: 11310
Here's a Self Debug Way
There are mainly 2 reason for this error. At this time you shall look the following steps to fix it by yourself.
/uploads
Note : You can have 755 permission
wp_options
has the value for upload_path
as wp-content/uploads
in it. (If not update it)Note : You can also update it at Settings>Media
Upvotes: 1