come faccio a incorporare un upload in questo script
cioe che uno completa il form
ed decide il file da uploadare
e poi schiaccia invia e sia i dati del form vengono inseriti nel database
e anche il file uploadato....poi vorrei che url del file venga scritto nel database sotto il campo
url
script form
Codice PHP:
<?php
if(isset($_POST['doupload'])){
$nome = $_GET['nome'];
$desc = $_GET['desc'];
$tipo = $_GET['tipo'];
$autore = $_GET['autore'];
$commento = $_GET['commento'];
$logo = $_GET['screen'];
$date = date("d-m-Y");
//conessione al database
require('config.php');
if($nome == NULL OR $desc == NULL OR $tipo == NULL OR $autore == NULL OR $commento == NULL OR $logo == NULL){
$final_report.= "Compilare tutti i campi..";
}else{
if(strlen($nome) <= 3 || strlen($nome) >= 30){
$final_report.="Il nome del gruppo deve conprendere dai 3 i 30 caratteri..";
}else{
if(strlen($desc) <= 3 || strlen($desc) >= 200){
$final_report.="Aggiungi una Descrizione per far trovare il tuo gruppo";
}else{
if(strlen($autore) <= 3 || strlen($autore) >= 30){
$final_report.="L'Autore del gruppo deve conprendere dai 3 i 30 caratteri..";
}else{
if(strlen($commento) <= 3 || strlen($commento) >= 250){
$final_report.="Nel commento Max caratteri 250";
}else{
$addgroup ="INSERT INTO Model3d (id,nome,desc,tipo,autore,logo,date) VALUES ('','$nome','$desc', '$tipo','$autore','$commento','$logo','$date')";
if(!mysql_query($addgroup,$dbh)) /*eseguo la query e controllo se va a buon fine ^^*/
die("<h1>".mysql_error()."</h1>");
mysql_close($db_nome);
header("Location: blog.php");
}}}}}}
?>
<form name="Form" method="post">
<table width="100%" align="left" >
<tr>
<td colspan="2"><div align="left"><strong>Add Model 3D</strong></td></div>
</tr>
<tr>
<br><td style="color: rgb(255, 0, 0);"><? echo '<tr><td colspan="2">'.$final_report.'</td></tr>';?></td><br>
</tr>
<tr>
<td width="16%"><strong>Nome Modello:</strong></td>
<td width="84%"><input type="text" name="nome"></td>
</tr>
<tr>
<td><strong>Comment:</strong></td>
<td><input type="text" name="desc" ></td>
</tr>
<tr>
<td width="16%"><b>Tipo Modello:</td></b><td width="84%"><select name="tipo">
<option value="dirty">Dirty</option>
<option value="race">Race</option>
<option value="hobby">Hobby</option>
<option value="videogames">Videogames</option>
<option value="team">Team</option>
<option value="suv">Suv</option>
<option value="other">Other</option>
</select></td>
</tr>
<tr>
<td width="16%"><strong>Autore Model</strong></td>
<td width="84%"><input type="text" name="autore"></td>
</tr>
<tr>
<td width="16%"><strong>Another Dettail</strong></td>
<td width="84%"><textarea name="commento" id="commento" rows="5" cols="39"></textarea></td>
</tr>
<td width="16%"><strong>ScreenShot Model</strong></td>
<td width="84%"><input type="url" name="logo"></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><div align="left">
<input type="submit" name="doupload" value="Add Model 3D">
</div></td>
</tr>
</table>
</form>
upload....ecco l'anteprima http://driver22.altervista.org/Addcars1.php non uploadate file per piacere
Codice PHP:
<?php
include_once "model3d.php";
$extlimit = "yes"; //Do you want to limit the extensions of files uploaded
$limitedext = array(".zip",".rar"); //Extensions you want files uploaded limited to.
$sizelimit = "no"; //Do you want a size limit, yes or no?
$sizebytes = "10000000"; //size limit in bytes
$dl = "/Track/"; //url where files are uploaded
$absolute_path = getcwd()."/Track/"; //Absolute path to where files are uploaded
$websiteurl = "http://Driver22.altervista.org"; //Url to you website
$websitename = "Home";
if (!isset($action)) {
$action = "";
}
switch($action) {
default:
echo"
<html>
<head>
<title>Add Track</title>
</head>
<body>
<a href=$PHP_SELF?action=upload class=button>Add Skin 2D</a>
</body>
</html>";
break;
case "upload":
echo"
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form method=POST action=$PHP_SELF?action=doupload enctype=multipart/form-data>
<p>File to upload:<br>
<input type=file name=file size=30>
<p><button name=doupload1 type=submit>
Upload
</button>
</form>
<br><br>
Powered by <a href=http://www.zachwhite.com/>PHP Uploader Downloader</a>
</body>
</html>";
break;
//File Upload
case "doupload1":
$dir = "dir";
if ($file != "") {
if (file_exists("$absolute_path/$file_name")) {
die("File already exists");
}
if (($sizelimit == "yes") && ($file_size > $sizebytes)) {
die("File is to big. It must be $sizebytes bytes or less.");
}
$ext = strrchr($file_name,'.');
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
die("The file you are uploading doesn't have the correct extension.");
}
@copy($file, "$absolute_path/$file_name") or die("The file you are trying to upload couldn't be copied to the server");
} else {
die("Must select file to upload");
}
echo "
<html>
<head>
<title>File Uploaded</title>
</head>
<body>";
echo $file_name." was uploaded";
echo "<br>
<a href=$PHP_SELF?action=upload>Upload Another Model 3d</a>
<a href=$websiteurl> Return to $websitename</a><br><br>
</body>
</html>";
break;
}
?>
<style type="text/css">
body{font: 76%/1.3 Arial,sans-serif;background:#FFF;color:#222}
a.button{display:block;width: 145px;height: 35px; margin: 1em;
font: bold 18px/35px "Trebuchet MS",Arial,sans-serif;
text-align:center;text-decoration: none; color: #286C98;
background: url(Registrazione/bottone2.png) no-repeat 0 0}
a.button:hover{background-position:0 -35px;color: #98286C}
</style>