I have a form for a non-profit-club, that publish posts + up to 20 images. The image-path will be writen in a custom-field. Images are uploaded. Ok, now i want to rename the pictures or (much better) create a folder. But there is a special: the form uploads 2 styles of images. There are up to 15 images for a wanted person (g) and up to 5 images for the person, who is missing this person (s). So i have to seperate the images at the server. The images are given from several input-fields.
I named the input-fields for "g" like:
<input type="file" name="image_1_gesucht" id="image_1_gesucht">
<input type="file" name="image_2_gesucht" id="image_2_gesucht">
...
<input type="file" name="image_15_gesucht" id="image_15_gesucht">
The field for "s" named like:
<input type="file" name="image_1_suchend" id="image_1_suchend">
<input type="file" name="image_2_suchend" id="image_2_suchend">
...
<input type="file" name="image_5_suchend" id="image_5_suchend">
If i can rename the pictures: I could do that with a prefix like g- or s- and a unique number. For the unique number i can use the post-id.
If i create a folder: Then i need a folder named like the post-id. If i can rename the pictures with the prefix, this one folder with the the post-id is ok. If i can't rename the pictures, i need 2 more subfolders - one for "g" and one for "s".
My existing script looks like the following example. I post this, that u can imagine the existing work. Can anybody tell me how to rename the pictures or to create folders? Sorry, i'm silly enough, that i don't can realise/understand, what the wordpress-codex want to tell me. There are two a little bit simiolar articles at stackexchange too ( Rename image uploads with width in filename and Issues renaming images during upload ), but also here: sorry, can't realise/understand. I relly hope, anybody can help me
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
$file=$_FILES;
// 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
$overrides = array( 'test_form' => false);
$image_1_gesucht = wp_handle_upload( $file['image_1_gesucht'], $overrides );
$image_2_gesucht = wp_handle_upload( $file['image_2_gesucht'], $overrides );
// 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>