Jump to content


Photo

Upload De Fotos


  • Faça o login para participar
Nenhuma resposta neste tópico

#1 To Maluco

To Maluco

    Novato no fórum

  • Usuários
  • 2 posts
  • Sexo:Masculino
  • Localidade:São Paulo

Posted 05/02/2011, 09:16

Boas pessoal estou precisando de uma ajudinha. Tenho um formulario de upload de 4 fotos só que esta acontecendo o seguinte,
Quando a pessoa seleciona apenas uma foto grava no banco quatro fotos, o codigo gera os numeros aleatorios.
Queria que os campos que estao em branco ou seja não foi selecionado foto não grave nada.

vai o codigo ai:

<?
require("AreaRestrita.php");
include("../includes/config.php");
?>
<html>
<head>
<!-- TinyMCE -->
<script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,

// Example content CSS (should be your site CSS)
content_css : "css/content.css",

// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",

// Style formats
style_formats : [
{title : 'Bold text', inline : 'b'},
{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
{title : 'Example 1', inline : 'span', classes : 'example1'},
{title : 'Example 2', inline : 'span', classes : 'example2'},
{title : 'Table styles'},
{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
],

// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
<!-- /TinyMCE -->

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cadastro</title>

<style type="text/css">
<!--
.style1 { font-family: Verdana, Arial, Helvetica, sans-serif;
color: #FFFFFF;
}
.style3 { color: #FFFFFF;
font-family: "Courier New", Courier, monospace;
font-weight: bold;
}
-->
</style>
</head>

<body>
<?

$data = date("d/m/Y");


################################
function initRand ()
{
static $randCalled = FALSE;
if (!$randCalled)
{
srand((double) microtime() * 1000000);
$randCalled = TRUE;
}
}
function randNum ($low, $high)
{
initRand();
$rNum = rand($low, $high);
return $rNum;
}
// setando o mínimo é o máximo que o número aleatório deve chegar

if($anunciante != ""){
if($file != "none"){
$num_imagem = randNum(0101,999999);

$f_name = $_FILES['file']['name'];
$ext = substr($f_name,-5);
$dir = $DirRoot."imagens/anunciantes";
$status = move_uploaded_file($file,"$dir"."/"."$num_imagem"."$ext");

// setando o mínimo é o máximo que o número aleatório deve chegar
}
}
if($anunciante != "name2"){
if($file2 != "none"){
$num_imagem2 = randNum(0101,999999);

$f_name2 = $_FILES['file2']['name2'];
$ext = substr($f_name,-5);
$dir = $DirRoot."imagens/anunciantes/imagem2";
$status = move_uploaded_file($file2,"$dir"."/"."$num_imagem2"."$ext");

// setando o mínimo é o máximo que o número aleatório deve chegar
}
}

if($anunciante != ""){
if($file3 != "none"){
$num_imagem3 = randNum(0101,999999);

$f_name3 = $_FILES['file3']['name3'];
$ext = substr($f_name,-5);
$dir = $DirRoot."imagens/anunciantes/imagem3";
$status = move_uploaded_file($file3,"$dir"."/"."$num_imagem3"."$ext");


}
}

if($anunciante != ""){
if($file4 != "none"){
// setando o mínimo é o máximo que o número aleatório deve chegar
$num_imagem4 = randNum(0101,999999);

$f_name4 = $_FILES['file4']['name4'];
$ext = substr($f_name,-5);
$dir = $DirRoot."imagens/anunciantes/imagem4";
$status = move_uploaded_file($file4,"$dir"."/"."$num_imagem4"."$ext");
}
}


if ($file != "none" || $file2 != "none" || $file3 != "none" || $file4 != "none" ) {
$cadastra = mysql_query("INSERT INTO anunciantes
(id_categoria,
anunciante,
endereco,
telefone,
email,
site,
descricao,
imagem,
imagem2,
imagem3,
imagem4,
exibe,
dt_cadastro)
VALUES
('$categoria',
'$anunciante',
'$endereco',
'$telefone',
'$email',
'$site',
'$descricao',
'$num_imagem$ext',
'$num_imagem2$ext',
'$num_imagem3$ext',
'$num_imagem4$ext',
'$exibe',
'$data')");
}else{
$cadastra = mysql_query("INSERT INTO anunciantes
(id_categoria,
anunciante,
endereco,
telefone,
email,
site,
descricao,
exibe,
dt_cadastro)
VALUES
('$categoria',
'$anunciante',
'$endereco',
'$telefone',
'$email',
'$site',
'$descricao',
'$exibe',
'$data')");
}
if($cadastra){
echo "<script>javascript:alert('Cacastrado com sucesso.');</script>";
}else{
echo mysql_error();
}

?>
<table align="center" width="450" border="0" cellspacing="0" cellpadding="0">
<tr><br />
<br />
<br />
<td bgcolor="#0178B3"><div align="center" class="style1 style3">Cadastro de Anunciante</div></td>
</tr>
</table>
<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data">
<label></label>
<label>

</label>
<table width="531" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Categoria:</font> </td>
<td><select name="categoria" id="categoria">
<?php combo_jornais ( -1 ); ?>
</select></td>
</tr>
<tr>
<td width="138">
<font face="Verdana, Arial, Helvetica, sans-serif" size="1">Nome do
produto:</font> </td>
<td width="393"><input name="anunciante" type="text" id="anunciante" size="40" /></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="1">Referencia:</font> </td>
<td><input name="endereco" type="text" id="endereco" size="40" /></td>
</tr>
<tr>
<td><font face="Verdana, Arial, Helvetica, sans-serif" size="1">
Valor(Opcional)</font></td>
<td><input name="telefone" type="text" id="telefone" size="40" /></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">E-mail:</font></td>
<td><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Site:</font></td>
<td><input name="site" type="text" id="site" size="40" /></td>
</tr>
<tr>
<td colspan="2" height="41"><b>Descrição do Produto</b></td>
</tr>
<tr>
<td colspan="2">
<textarea id="elm1" name="descricao" rows="15" cols="80" style="width: 300; height:350"></textarea></td>
</tr>
<tr>
<td>
<p align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Imagem:</font></td>
<td><input name="file" type="file" class="campoform"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="file2" type="file" class="campoform" size="20"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="file3" type="file" class="campoform" size="20"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="file4" type="file" class="campoform" size="20"></td>
</tr>
<tr>
<td>
<p align="right"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Exibir?:</font></td>
<td><label>
<input name="exibe" type="radio" id="radio" value="1" checked>
</label>
<font size="1" face="Verdana, Arial, Helvetica, sans-serif">Sim</font>
<label>
<input name="exibe" type="radio" id="radio2" value="0">
</label>
<font size="1" face="Verdana, Arial, Helvetica, sans-serif">N&atilde;o</font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Cadastrar" /></td>
</tr>
</table>
</form>
</body>
</html>
<?
// jornais

function combo_jornais ( $id_categorias )

{

global $Connection;

$sSql = " SELECT * ";
$sSql .= " FROM categorias";
$sSql .= " ORDER BY id ";

$Result = mysql_query( $sSql );

if ( !$Result )
exit( " Erro : ao Procurar Dados das categorias = > " . mysql_error());

while( $aResult = mysql_fetch_array( $Result ) )

{

if ( $id_categorias == $aResult["id"] )
print "<option value=\"" . $aResult["id"] . "\" selected >" . $aResult["categoria"] . "</option>\n";
else
print "<option value=\"" . $aResult["id"] . "\" >" . $aResult["categoria"] . "</option>\n";

}

}
?>

Se alguem poder me ajudar agradeço muito




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq