Good afternoon. I started this week in a PHP development company. I need to include a combobox on a page that uploads files. The upload already works and has been used.
** I would like help to save the selected value in the combobox in the same table of the files (which the client chose to upload). This combobox shows the "File Category" and will serve to classify the client's images / documents.
files.php // File containing the combobox and also the button to upload the files.
<div class="form-group"> Categoria do Arquivo
<form name="formCatArq" id="formCatArq" method="post" >
<select class="form-control" style="width:40%" name="arqcat_codigo" id="arqcat_codigo" >
<option value="-1" selected="selected">Selecione a Categoria do Arquivo</option>
<?php
//CARREGA LISTA DE CATEGORIAS
$sql_gru = "select * from arquivos_categorias $sql_cat where arqcat_ativo ='S' order by arqcat_titulo asc ";
$qry_gru = mysql_query($sql_gru);
if (mysql_num_rows($qry_gru) > 0) {
while ($row = mysql_fetch_array($qry_gru)) {?>
<option value="<?php echo $row['arqcat_codigo']?>" <? if ($marqcat_codigo == $row['arqcat_codigo']) {echo 'selected="selected"'; } ?>> <?php echo $row['arqcat_titulo']; ?> </option>
<?php }
}?>
</select>
<label>
<input type="submit" name="btnEnviar" id="btnEnviar" value="Filtrar sua busca:" />
</label>
</form>
</div>
// Botão para realizar o "Upload"
<div id="mulitplefileuploader_arquivos">Upload</div>
Index.php // contains script to get the value of the combobox and in the sequence calls the function "send_value" in an attempt to load the value of the combobox together with the upload function. I'm trying to send the variable "$ arqcat" along with the "url:" parameter of the "settings_arq" variable, but this value does not arrive on the "upload_arquivos.php" page that inserts into the database.
<script>
$(function() {
$('#arqcat_codigo').change(function(){
var tip = $("#arqcat_codigo").val();
if (($('#arqcat_codigo').val() == '-1') || (tip == '-1'))
{
alert('Selecione a Categoria do Arquivo');
}
else {
envia_valor(tip);
}
});
});
</script>
<script>
function envia_valor(tip) {
$arqcat = tip;
$(document).ready(function(){
// alert($arqcat);
var settings_arq = {
url: "upload_arquivos.php?cod=<?=$codigo?>&usucatcod=<?=$usucat?>&arqcatcodigo=<?=$arqcat?>",
method: "POST",
fileName: "myfile",
multiple: true,
showProgress: true,
showStatusAfterSuccess: true,
dragDropStr: "<span><b>Selecione os arquivos para upload23332</b></span>",
onSuccess:function(files,data,xhr)
{
$("#status").html("<font color='green'>Upload realizado com sucesso</font>");
location.reload();
},
onError: function(files,status,errMsg)
{
$("#status").html("<font color='red'>Falha no upload</font>");
}
}
$("#mulitplefileuploader_arquivos").uploadFile(settings_arq);
});
};
</script>
upload_files.php // receives the parameters and generates the sql.
<?php
if(isset($_FILES["myfile"]))
{
$ret = array();
$error =$_FILES["myfile"]["error"];
{
if(!is_array($_FILES["myfile"]['name'])) //single file
{
$arquivo = $_FILES["myfile"];
$nome_temp = $arquivo["tmp_name"];
$nome_arquivo = $cod . "-" . $arquivo["name"];
$nome_arquivo = str_replace(' ', '', $nome_arquivo);
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $nome_arquivo);
$ret[$arquivo]= $output_dir.$arquivo;
$sql = "insert into arquivos (usu_codigo, arqcat_codigo, usucat_codigo, arq_legenda, arq_arquivo, arq_data, arq_imagem) values($cod, '$arqcatcodigo', '$usucatcod', '$arquivo[name]','$nome_arquivo',curdate(),'N')";
$post = mysql_query($sql);
$codigo = mysql_insert_id();
$ext = strxchr($nome_arquivo, ".", 1, 1);
$ext = substr(strtolower($ext[1]),1);
if ($ext=='jpg' || $ext=='jpeg' || $ext=='png') {
GerarImagens($nome_arquivo, 200, 'thumb_');
GerarImagens($nome_arquivo, 227, 'gal_');
$sql2 = "update arquivos set arq_imagem='S' where arq_codigo=$codigo";
$qry2 = mysql_query($sql2);
}
}
}
echo json_encode($ret);
}
?>