Hi Guys
Nice website, i have a little problem regarding a uploading form with inserting post from frontend with post attachment, i am trying to upload zip files and after the zip file is uploaded the Wordpress need to handle the zip file by autoextracting and inserting like media into that post.
Here is my code
<?php /* Template Name: Add New Album Zip22*/
get_header(); ?>
<div class="container">
<div class="col-md-8 add_album">
<?php
include_once ABSPATH . 'wp-admin/includes/media.php';
include_once ABSPATH . 'wp-admin/includes/file.php';
include_once ABSPATH . 'wp-admin/includes/image.php';
//Random Id post generation
$randomid = rand(5, 9999);
if (isset($_POST['categorite'])) {
$categorite = $_POST['categorite'];
}
if ( !empty( $_POST['post_title'] ) ) {
// Create post object
$my_post = array(
'post_title' => wp_strip_all_tags( $_POST['post_title'] ),
'post_content' => wp_strip_all_tags( $_POST['post_content'] ),
'post_status' => 'pending',
'import_id' => $randomid,
'post_category' => $categorite
);
// Insert the post into the database
$parent_post_id = wp_insert_post( $my_post );
WP_Filesystem();
$destination = wp_upload_dir();
$destination_path = $_POST['image_upload'];
$unzipfile = unzip_file( $destination_path.'/filename.zip', $destination_path);
if ( $unzipfile ) {
echo 'Successfully unzipped the file!';
} else {
echo 'There was an error unzipping the file.';
}
$attachment_id = media_handle_upload( 'image_upload' , $randomid );
//add post thumbnail to the post
$attachment_id_post_thumbnail = media_handle_upload( 'post_thumbnail_album' , $randomid );
$postthumb = set_post_thumbnail( $randomid, $attachment_id_post_thumbnail );
// Insert the attachment.
//$attach_id = wp_insert_attachment( $attachment_id , $filename, $parent_post_id );
// Generate the metadata for the attachment, and update the database record.
wp_update_attachment_metadata($parent_post_id, $attachment_id );
}?>
<h2>Add you Album</h2>
<p>In order to view the album after you inserted it should be approved from the administrator</p>
<form action="" method="post" enctype="multipart/form-data">
<fieldset>
<label>Album Category</label>
<?php $categories = get_categories(array('hide_empty'=> 0));
foreach ( $categories as $category ) { ?>
<input type="checkbox" name="categorite[]" value="<?php echo $category->cat_ID;?>">
<?php echo $category->cat_name; ?>
<?php }?>
</fieldset>
<fieldset>
<label for="post_title"><?php _e('Album Title:', 'framework') ?></label>
<input type="text" name="post_title" id="post_title" />
</fieldset>
<fieldset>
<label for="post_content"><?php _e('Album Desription:', 'framework') ?></label>
<textarea name="post_content" id="post_content" rows="8" cols="30"></textarea>
</fieldset>
<fieldset>
<label>Album Image</label>
<input type="file" name="post_thumbnail_album" id="post_thumbnail_album" multiple="false" />
</fieldset>
<fieldset>
<label>Album song</label>
<input type="file" name="image_upload" id="image_upload" multiple="false" />
</fieldset>
<?php echo $master; ?>
<button type="submit"><?php _e('Insert Album', 'framework') ?></button>
</form>
</div>
<div class="row">
<?php get_sidebar( 'home' ); ?>
</div>
<?php get_footer();?>
Fahad Murtaza answers:
Create a bash script that does it for you.
klevi_surf comments:
I need to do from php side, not from bash
Fahad Murtaza comments:
OK!
klevi_surf comments:
Hello Guys, any news?
klevi_surf comments:
Hello Guys, any news?
Fahad Murtaza comments:
Hi klevi
Nobody is going to help you actually code with such a small amount ;)
klevi_surf comments:
Sorry? so i pay for nothing??? money back?
Fahad Murtaza comments:
yeah why not. Please go ahead.
klevi_surf comments:
means?
klevi_surf comments:
Fuck you!
Fahad Murtaza comments:
Likewise :)
Fahad Murtaza comments:
Thanks for being so nice :)
klevi_surf comments:
I payed a requested payment for a service and not come out was for nothing? thank you for being so proffesional!!!
Fahad Murtaza comments:
I wasn't trying to be rude. You asked for a solution which takes considerable amount of time for someone to actually help you and you are not being reasonable.
May be I sounded rude but I wasn't. Anyhow, good luck for the work.
klevi_surf comments:
Ok the minimum price was what you requested, nobody setted up your minimal price! and now you are saying me that was a little price? For little things i can figure out myself! Be more specific in the future with the other clients! What about my payment????
klevi_surf comments:
what about my payment?????
Fahad Murtaza comments:
My clients are not rude like you and I chose them wisely and which payment are you talking about?
klevi_surf comments:
The 2.76 USD i payed for the service via paypal! You do not know for what payment i am talking about???