I am doing a plugin for wordpress a CRUD and I have decided in my form to add a input
type file to upload images (which I only want to save the path of the image only once moved to my server)
<form method="POST" ENCTYPE="multipart/form-data">
<input type="text" name="Nombre" value="<?php echo $name; ?>" class="ss-field-width" />
<input type="file" name="img" value="<?php echo $img; ?>" class="ss-field-width" />
<input type='submit' name="insert" value='Guardar' class='button'>
</form>
and it turns out that when sending the data the variables using $_FILE[]
arrive empty but those that you have $_POST[]
if I get the information
$imgname=$_FILES["img"]["name"];
$tipo_imagen=$_FILES["img"]["type"];
$tamagno_imagen=$_FILES["img"]["size"];
$tmp=$_FILES["img"]["tmp_name"];
and that does not allow me to put the data into my database (which I'm using
global $wpdb;
to insert my data)
global $wpdb;
$table_name = $wpdb->prefix . "mitabla";
$wpdb->insert(
$table_name, //table
array(
'img'=>$imgname
), //data
array('%s', '%s') //data format
);
which in my form using the enctype="multipart/form-data"
I get the data to my $_FILE
but I do not insert it into my database, but if I remove it from my form the enctype="multipart/form-data"
I get all empty fields using $_FILE[]
but if it manages to put my database in this case only the input name that is type text (because for the text type I use $_POST[]
).
Why is this happening? Is there another option to upload an image to a database through a form in Wordpress?