Formulario com Anexo e MySQL
Boa Tarde amigos,
Estou tentando fazer um formulario com envio de anexos para dar insert no banco,
Eu consegui fazer os dois separados, somente texto ou somente o arquivo, agora como eu junto os dois ?
dessa maneira ele sobe somente o arquivo mas não o campo nome, podem me ajudar ?
muito obrigado
ARQUIVO UPLOAD.PHP
<?php
include_once 'dbconfig.php';
if(isset($_POST['btn-upload']))
{
$file = rand(1000,100000)."-".$_FILES['file']['name'];
$file_loc = $_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$folder="uploads/";
$nome =$_POST["Nome"];
// new file size in KB
$new_size = $file_size/1024;
// new file size in KB
// make file name in lower case
$new_file_name = strtolower($file);
// make file name in lower case
$final_file=str_replace(' ','-',$new_file_name);
if(move_uploaded_file($file_loc,$folder.$final_file))
{
$sql="INSERT INTO tbl_uploads(file,type,size,Nome) VALUES('$final_file','$file_type','$new_size', '$Nome')";
mysql_query($sql);
?>
<script>
alert('successfully uploaded');
window.location.href='index.php?success';
</script>
<?php
}
else
{
?>
<script>
alert('error while uploading file');
window.location.href='index.php?fail';
</script>
<?php
}
}
?>
ARQUIVO INDEX.HTML
<?php
include_once 'dbconfig.php';
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>File Uploading With PHP and MySql</title>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="header">
<label>teste Upload</label>
</div>
<div id="body">
<form action="upload.php" method="post" enctype="multipart/form-data">
Nome: <br />
<input type="text" name="Nome" size="65" style="margin-left:0px; float:left;" /><br><br />
<input type="file" name="file" />
<button type="submit" name="btn-upload">upload</button>
</form>
<br /><br />
<?php
if(isset($_GET['success']))
{
?>
<label><a href="view.php">Ver arquivo.</a></label>
<?php
}
else if(isset($_GET['fail']))
{
?>
<label>problema no upload</label>
<?php
}
else
{
?>
<label></label>
<?php
}
?>
</div>
<div id="footer">
</div>
</body>
</html>Discussão (4)
Carregando comentários...