I build a script, to post from frontend. There are many custom-fields. Most works fine, but with one thing i have problems.
First a description, then the script.
It seems like, that images won't upload, cause i can't find them in the upload-directory or anywhere else. The cutom-field will be generated, that's no problem. I say that, cause the field appears at the backend - but empty. I think it's empty, cause it doesn't upload. Yes, for testing i have put 777 to my serversettings for the upload-directory, so i think the server is not disabling the upload.
P.S.: I shortened the code to make it clear. If you want the hole code, just say a word.
Thank you for helping!
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
// Funktion zum Image-Upload, falls sie noch nicht existiert
if ( ! function_exists( 'wp_handle_upload' )) {
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
// Variablen für die Bilder
$image_1_gesucht = wp_handle_upload( $file['image_1_gesucht'] );
$image_2_gesucht = wp_handle_upload( $file['image_2_gesucht'] );
// Benutzerdefinierfte Felder für die Bilder
add_post_meta($pid,'image_1_gesucht',$image_1_gesucht['url']);
add_post_meta($pid,'image_2_gesucht',$image_2_gesucht['url']);
}
<form id="new_post" name="new_post" method="post" action="" enctype="multipart/form-data">
<div class="pro50left">
<fieldset class="images">
<label for="images">Bild 1:</label>
<input type="file" name="image_1_gesucht" id="image_1_gesucht">
</fieldset>
</div>
<div class="pro50left">
<fieldset class="images">
<label for="images">Bild 2:</label>
<input type="file" name="image_2_gesucht" id="image_2_gesucht">
</fieldset>
</div>
</form>