Arquivado
Este tópico foi arquivado e está fechado para novas respostas.
Erro repentino em upload de arquivos (sem uso de componentes de terce
Por
ronaldoflopes, em ASP Clássico
Recommended Posts
-
Conteúdo Similar
-
Por davidnmagalhaes
Olá prezados,
Estou com uma grande dúvida para fazer o upload de arquivos no banco de dados, eu consigo enviar os arquivos normalmente utilizando o move_uploaded_file, porém o meu problema é que no banco de dados aparece apenas um arquivo, vamos supor que o cliente envie 3 arquivos, os três arquivos aparecem na pasta ao efetuar o upload, porém no banco de dados aparece apenas um dos arquivos, segue abaixo o código da página:
<?php require_once('Connections/conteste.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { if(isset($_FILES['file'])) { $name = $_FILES['file']['name']; $type = $_FILES['file']['type']; $size = $_FILES['file']['size']; } $message = ''; if(is_array($_FILES['file']['error'])) { foreach ($_FILES['file']['error'] as $code) { switch ($code) { case UPLOAD_ERR_OK: $message .= ""; break; case UPLOAD_ERR_INI_SIZE: $message .= "O upload do arquivo excedeu o tamanho máximo de upload (upload_max_filesize) do php.ini<br/>"; break; case UPLOAD_ERR_FORM_SIZE: $message .= "O upload do arquivo excedeu o tamanho máximo de upload (MAX_FILE_SIZE) que foi especificado no formulário HTML<br/>"; break; case UPLOAD_ERR_PARTIAL: $message .= "O upload do arquivo foi carregado parcialmente<br/>"; break; case UPLOAD_ERR_NO_FILE: $message .= "Nenhum arquivo foi carregado<br/>"; break; case UPLOAD_ERR_NO_TMP_DIR: $message .= "Missing a temporary folder<br/>"; break; case UPLOAD_ERR_CANT_WRITE: $message .= "Falha ao escrever o arquivo no disco<br/>"; break; case UPLOAD_ERR_EXTENSION: $message .= "File upload stopped by extension<br/>"; break; default: $message .= "Erro de Upload Desconhecido<br/>"; break; } } } elseif(isset($_FILES['file']['error'])) { $code = $_FILES['file']['error']; switch ($code) { case UPLOAD_ERR_OK: $message .= ""; break; case UPLOAD_ERR_INI_SIZE: $message .= "The uploaded file exceeds the upload_max_filesize directive in php.ini<br/>"; break; case UPLOAD_ERR_FORM_SIZE: $message .= "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form<br/>"; break; case UPLOAD_ERR_PARTIAL: $message .= "The uploaded file was only partially uploaded<br/>"; break; case UPLOAD_ERR_NO_FILE: $message .= "No file was uploaded<br/>"; break; case UPLOAD_ERR_NO_TMP_DIR: $message .= "Missing a temporary folder<br/>"; break; case UPLOAD_ERR_CANT_WRITE: $message .= "Failed to write file to disk<br/>"; break; case UPLOAD_ERR_EXTENSION: $message .= "File upload stopped by extension<br/>"; break; default: $message .= "Unknown upload error<br/>"; break; } } elseif(!isset($_FILES['file'])) { $message = "No files recieved<br/>"; } $uploaddir = 'pedidos'; if(is_array($_FILES['file']['name'])) { foreach ($_FILES['file']['name'] as $k=>$filename) { for ($k = 0; $k < count($_FILES['file']['name']); $k++){ $uploadfile = getcwd()."/".$uploaddir."/".$k.$filename; if(move_uploaded_file($_FILES['file']['tmp_name'][$k], $uploadfile)) { // ok } else { $message .= "Erro enquanto carregava o arquivo ".$filename."<br/>"; } }//fecha } } elseif(isset($_FILES['file']['name'])) { for ($k = 0; $k < count($_FILES['file']['name']); $k++){ $uploadfile = getcwd()."/".$uploaddir."/".$_FILES['file']['name'][$k]; if(move_uploaded_file($_FILES['file']['tmp_name'][$k], $uploadfile)) { // ok } else { $message = "Erro enquanto carregava o arquivo ".$_FILES['file']['name']."<br/>"; } }//fecha } $insertSQL = sprintf("INSERT INTO pedidos (id, nome, empresa, telefone, celular, email, observacoes, arquivos) VALUES (%s, %s, %s, %s, %s, %s, %s, '$uploadfile')", GetSQLValueString($_POST['id'], "int"), GetSQLValueString($_POST['nome'], "text"), GetSQLValueString($_POST['empresa'], "text"), GetSQLValueString($_POST['telefone'], "int"), GetSQLValueString($_POST['celular'], "int"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['observacoes'], "text")); mysql_select_db($database_conteste, $conteste); $Result1 = mysql_query($insertSQL, $conteste) or die(mysql_error()); $insertGoTo = "envio-sucesso.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?> <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento sem título</title> <link rel="shortcut icon" href="../favicon.ico"> <link rel="stylesheet" type="text/css" href="css/demo.css" /> <link rel="stylesheet" type="text/css" href="css/style1.css" /> <link rel="stylesheet" type="text/css" media="all" href="styles.css" /> <link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css"> <link rel="stylesheet" href="pe-icon-7-stroke/css/pe-icon-7-stroke.css"> <link rel="stylesheet" href="css/drop_uploader.css"> <script type="text/javascript" src="js/modernizr.custom.86080.js"></script> <script src="js/jquery-2.2.4.min.js"></script> <script src="js/drop_uploader.js"></script> <script> $(document).ready(function(){ $('input[type=file]').drop_uploader({ uploader_text: 'Drop files to upload, or', browse_text: 'Browse', browse_css_class: 'button button-primary', browse_css_selector: 'file_browse', uploader_icon: '<i class="pe-7s-cloud-upload"></i>', file_icon: '<i class="pe-7s-file"></i>', time_show_errors: 5, }); }); </script> </head> <body id="page"> <ul class="cb-slideshow"> <li><span>Image 01</span><div><h3></h3></div></li> <li><span>Image 02</span><div><h3></h3></div></li> <li><span>Image 03</span><div><h3></h3></div></li> <li><span>Image 04</span><div><h3></h3></div></li> <li><span>Image 05</span><div><h3></h3></div></li> <li><span>Image 06</span><div><h3></h3></div></li> </ul> <div class="container"> <div id="logo"><img src="images/logo.png"/></div> <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1"> <h1 id="titulo-upload">Upload de Arquivos</h1> <div id="itens-form"> <div class="twelve column"><input type="file" name="file[]" multiple></div> <p> <input type="hidden" name="id" id="id" /> <input type="text" name="empresa" id="empresa" class="campos" placeholder="Empresa"/> </p> <p> <input type="text" name="nome" id="nome" class="campos" placeholder="Nome completo"/> </p> <p> <input type="text" name="telefone" id="telefone" class="campos" placeholder="Telefone"/> </p> <p> <input type="text" name="celular" id="celular" class="campos" placeholder="Celular"/> </p> <p> <input type="text" name="email" id="email" class="campos" placeholder="E-mail"/> </p> <p> <textarea name="observacoes" id="observacoes" cols="45" rows="5" placeholder="Observações"></textarea> </p> <p> <input type="submit" name="enviar" id="enviar" value="Enviar" /> </p> <input type="hidden" name="MM_insert" value="form1" /> </div> </form> <div class="clr"></div> </div><!--/ Codrops top bar --> </div> </body> </html> -
Por leoamrl
Estou trabalhando no desenvolvimento de um theme wordpress do zero e estou colocando uma página de "Theme Settings" nesse theme, para alterar coisas como a logo, links de ícones, copyright etc.
Para fazer o Painel segui esse tutorial: http://wpmidia.com.br/tutoriais/tutorial-wordpress-como-criar-abas-em-sua-theme-options-page
Preciso de um código HTML para colocar no Theme Settings em que eu possa fazer o upload de uma imagem, e armazenar no wordpress para que seja usada como logo.
Meu código está assim:
Arquivo adminsettings.php
<?php add_action( 'init', 'wptester_admin_init' ); add_action( 'admin_menu', 'wptester_settings_page_init' ); function wptester_admin_init() { $settings = get_option( "wptester_theme_settings" ); if ( empty( $settings ) ) { $settings = array( 'wptester_intro' => 'Some intro text for the home page', 'wptester_tag_class' => false, 'wptester_ga' => false ); add_option( "wptester_theme_settings", $settings, '', 'yes' ); } } function wptester_settings_page_init() { $theme_data = get_theme_data( TEMPLATEPATH . '/style.css' ); $settings_page = add_theme_page( $theme_data['Name']. ' Theme Settings', $theme_data['Name']. ' Theme Settings', 'edit_theme_options', 'theme-settings', 'wptester_settings_page' ); add_action( "load-{$settings_page}", 'wptester_load_settings_page' ); } function wptester_load_settings_page() { if ( $_POST["wptester-settings-submit"] == 'Y' ) { check_admin_referer( "wptester-settings-page" ); wptester_save_theme_settings(); $url_parameters = isset($_GET['tab'])? 'updated=true&tab='.$_GET['tab'] : 'updated=true'; wp_redirect(admin_url('themes.php?page=theme-settings&'.$url_parameters)); exit; } } function wptester_save_theme_settings() { global $pagenow; $settings = get_option( "wptester_theme_settings" ); if ( $pagenow == 'themes.php' && $_GET['page'] == 'theme-settings' ){ if ( isset ( $_GET['tab'] ) ) $tab = $_GET['tab']; else $tab = 'homepage'; switch ( $tab ){ case 'general' : $settings['wptester_tag_class'] = $_POST['wptester_tag_class']; break; case 'footer' : $settings['wptester_ga'] = $_POST['wptester_ga']; break; case 'homepage' : $settings['wptester_intro'] = $_POST['wptester_intro']; break; } } if( !current_user_can( 'unfiltered_html' ) ){ if ( $settings['wptester_ga'] ) $settings['wptester_ga'] = stripslashes( esc_textarea( wp_filter_post_kses( $settings['wptester_ga'] ) ) ); if ( $settings['wptester_intro'] ) $settings['wptester_intro'] = stripslashes( esc_textarea( wp_filter_post_kses( $settings['wptester_intro'] ) ) ); } $updated = update_option( "wptester_theme_settings", $settings ); } function wptester_admin_tabs( $current = 'homepage' ) { $tabs = array( 'homepage' => 'Home', 'general' => 'General', 'footer' => 'Footer' ); $links = array(); echo '<div id="icon-themes" class="icon32"><br></div>'; echo '<h2 class="nav-tab-wrapper">'; foreach( $tabs as $tab => $name ){ $class = ( $tab == $current ) ? ' nav-tab-active' : ''; echo "<a class='nav-tab$class' href='?page=theme-settings&tab=$tab'>$name</a>"; } echo '</h2>'; } function wptester_settings_page() { global $pagenow; $settings = get_option( "wptester_theme_settings" ); $theme_data = get_theme_data( TEMPLATEPATH . '/style.css' ); ?> <div class="wrap"> <h2>Theme Settings</h2> <?php if ( 'true' == esc_attr( $_GET['updated'] ) ) echo '<div class="updated" ><p>Theme Settings updated.</p></div>'; if ( isset ( $_GET['tab'] ) ) wptester_admin_tabs($_GET['tab']); else wptester_admin_tabs('homepage'); ?> <div id="poststuff"> <form method="post" action="<?php admin_url( 'themes.php?page=theme-settings' ); ?>"> <?php wp_nonce_field( "wptester-settings-page" ); if ( $pagenow == 'themes.php' && $_GET['page'] == 'theme-settings' ){ if ( isset ( $_GET['tab'] ) ) $tab = $_GET['tab']; else $tab = 'homepage'; echo '<table class="form-table">'; switch ( $tab ){ case 'general' : ?> <tr> <th><label for="wptester_tag_class">Tags with CSS classes:</label></th> <td> <input id="wptester_tag_class" name="wptester_tag_class" type="checkbox" <?php if ( $settings["wptester_tag_class"] ) echo 'checked="checked"'; ?> value="true" /> <span class="description">Output each post tag with a specific CSS class using its slug.</span> </td> </tr> <?php break; case 'footer' : ?> <tr> <th><label for="wptester_ga">Insert tracking code</label></th> <td> <textarea id="wptester_ga" name="wptester_ga" cols="60" rows="5"><?php echo esc_html( stripslashes( $settings["wptester_ga"] ) ); ?></textarea><br/> <span class="description">Enter your Google Analytics tracking code</span> </td> </tr> <?php break; case 'homepage' : ?> <tr> <th><label for="wptester_intro">Text Logo</label></th> <td> <textarea id="wptester_intro" name="wptester_intro" cols="60" rows="5" ><?php echo esc_html( stripslashes( $settings["wptester_intro"] ) ); ?></textarea><br/> <span class="description">Digite o texto que irá aparecer na área da logo:</span> </td> </tr> <?php break; } echo '</table>'; } ?> <p class="submit" style="clear: both;"> <input type="submit" name="Submit" class="button-primary" value="Update Settings" /> <input type="hidden" name="wptester-settings-submit" value="Y" /> </p> </form> </div> </div> <?php } Arquivo functions.php
<?php /* WIDGETS */ if (function_exists('register_sidebar')) { register_sidebar(array( 'name' => 'Sidebar', 'before_widget' => '<div class="widget">', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>', )); } register_nav_menu( 'main-menu', 'Menu Principal' ); /* Load up our theme options page and related code. */ if ( is_admin() ) require_once( TEMPLATEPATH . '/adminsettings.php' ); ?> Arquivo header.php [sAÍDA DAS INFORMAÇÕES DIGITADAS NO PAINEL DE ADMIN]
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml"> <head> <title><?php wp_title(''); ?></title> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="profile" href="http://gmpg.org/xfn/11" /> <link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /> <link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" /> <?php if ( is_singular() && get_option( 'thread_comments' ) ) wp_enqueue_script( 'comment-reply' ); wp_head(); ?> </head> <body> <header id="header-geral"> <div class="container"> <a href="./index.php"><?php $opcoes = get_option('wptester_theme_settings'); echo $opcoes['wptester_intro']; ?></a> <nav> <?php wp_nav_menu( array( 'location'=>'main-menu', 'container'=>'div', 'container-class'=>'menu', 'menu_class'=>'ul-menu' ) ); ?> </nav> </div> </header> Agradeço a atenção e a ajuda.
-