Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function create_gallery() {
- global $post;
- echo '<input type="hidden" name="mytheme_meta_box_nonce" value="' . wp_create_nonce(basename(__FILE__)) . '" />';
- $slider_image = get_post_meta($post->ID, 'slider_image', true);
- $main_image = get_post_meta($post->ID, 'main_image', true);
- $gallery = get_post_meta($post->ID, 'gallery', true);
- ?>
- <form id = "car_uploads" name="car_uploads" action="" method="post" enctype="multipart/form-data">
- <table width = "100%">
- <tr>
- <td width = "130px"><label for="slider_image"><?php _e("Slider Image: ", 'slider_image' ); ?></label></td>
- <td><input type="file" id="slider_image" name="slider_image" /></td>
- </tr>
- <tr>
- <td><label for="main_image"><?php _e("Main Image: ", 'main_image' ); ?></label></td>
- <td><input type="file" id="main_image" name="main_image" /></td>
- </tr>
- <tr>
- <td><label for="gallery"><?php _e("Gallery: ", 'gallery' ); ?></label></td>
- <td><input type="file" id="gallery" name="gallery" /></td>
- </tr>
- </table>
- <input type="submit" name="uploadImages" value="Upload images" />
- <?php //submit_button( 'Upload images', 'secondary', 'uploadImages', false) ?>
- </form>
- <?php
- }
- echo "A";
- ?>
- <?php
- define("MAX_SIZE","3000");
- $errors = 0;
- $inputFiles = array('slider_image', 'main_image', 'gallery');
- if(isset($_POST['uploadImages'])){
- echo "B";
- foreach($inputFiles as $key => $value){
- $image = $_FILES[$value]['name'];
- if ($image){
- $filename = stripslashes($_FILES[$value]['name']);
- $extension = getExtension($filename);
- $extension = strtolower($extension);
- if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")){
- echo '<h3>Unknown file extension! Only jpeg, png and gif are accepted.</h3>';
- $errors = 1;
- }else{
- $size = filesize($_FILES[$value]['tmp_name']);
- if ($size > MAX_SIZE*1024){
- echo '<h1>You have exceeded the size limit!</h1>';
- $errors=1;
- }
- $image_name = $filename;
- $newname = $upload_dir . "/cars/".$image_name;
- $copied = copy($_FILES[$value]['tmp_name'], $newname);
- if (!$copied){
- echo '<h3>The file upload was unsuccessfull!</h3>';
- $errors=1;
- }
- }
- }
- echo "D";
- $existsSql = "SELECT * FROM wp_candv_candvadmin_cars WHERE name = '" . $filename . "'";
- $bannerImageExists = $wpdb->get_results($existsSql);
- if(count($bannerImageExists)!=0){
- echo "<h3>The image '" . $filename . "' already exists in the database!</h3>";
- }else{
- $wpdb->insert( $candvAdmin_cars_table_name, array(
- 'time' => current_time('mysql'),
- 'name' => $filename,
- 'fileType' => $extension,
- 'fileSize' => $size,
- 'fileSrc' => $newname,
- 'listOrder' => 0,
- 'postId' => $currentPost,
- ), array(
- '%s',
- '%s',
- '%s',
- '%d',
- '%s',
- '%d',
- '%d',
- ) );
- echo "<h3>File Uploaded Successfully!</h3>";
- }
- }
- }else{
- echo "C";
- }
- /*if(isset($_POST['delete'])){
- $theImages = $_POST['bannerImages'];
- $i = 0;
- while($i<count($theImages)){
- $wpdb->query("DELETE FROM wp_candv_candvadmin_cars WHERE name = '" . $theImages[$i] . "'");
- $i++;
- }
- } */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement