dragem Posted April 5, 2007 Share Posted April 5, 2007 ok i need help with a script right now i got a script that uploads and put some data in the database here is a pic of the script at work what i wanna get is a script were users also can give a name and discription. can anyone help me with it <?php session_start(); $id=$_GET["id"]; $title="Fotos Toevoegen" ; include("head.php"); include("open_db.php"); include("securetop.php"); echo $_FILES["bestand"]["name"]; $queryalbum = "SELECT * FROM albums where albumid = $id "; $resultalbum = mysql_query($queryalbum) or die("Fout bij uitvoeren query"); $linealbum = mysql_fetch_array($resultalbum, MYSQL_ASSOC); error_reporting(E_ALL); $uploadmap = "upload"; $teken="\\"; $map = $uploadmap.$teken.$linealbum["mapnaam"].$teken; // Map waar alles geupload wordt function upload_file($fTmp, $fNew) { if(file_exists($fNew)) { return false; } else { copy($fTmp, $fNew); return true; } } if(Isset($_POST['submit'])) { for($i = 0; $i < count($_FILES['bestand']['name']); $i++) { if(Isset($_FILES['bestand']['name'][$i]) && is_uploaded_file($_FILES['bestand']['tmp_name'][$i])) { if(!upload_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) { $error = true; } } } if(IsSet($error)) { echo "Mislukt!"; exit; } else { echo "Gelukt!"; $aantalfoto = count($_FILES['bestand']['name']); $query= ("INSERT INTO fotos (bestandsnaam, albumid) VALUES"); for($tel=0; $tel < $aantalfoto; $tel++){ if ($tel == 0){ $query .= "(\"" . $_FILES['bestand']['name'][$tel] . "\", \"" . $id . "\")"; } else { if($_FILES['bestand']['name'][$tel]==true){ $query .= ",(\"" . $_FILES['bestand']['name'][$tel] . "\", \"" . $id . "\")"; } } } $result = mysql_query($query) or die("Fout bij uitvoeren query"); } } else { if(IsSet($_POST['aantal'])) { $aantal = $_POST['aantal']; } else { $aantal = 5; } ?> <form action="" method="post"> <input type="text" name="aantal" value="<?php echo $aantal; ?>" size="1"> <input type="submit" name="aantal_submit" value="Aantal bestanden"> </form> zorg dat u zowiezo de eerste invult en upload een foto maar 1 keer <br><br> <form action="" method="post" enctype="multipart/form-data"> <?php for($i = 0; $i < $aantal; $i++) { ?> Bestand <?php echo $i + 1; ?>: <input type="file" name="bestand[<?php echo $i; ?>]"><br> <?php } ?> <input type="submit" name="submit" value="Uploaden"> </form> <?php } include("close_db.php"); ?> Link to comment https://forums.phpfreaks.com/topic/45715-solved-help-with-upload-script/ Share on other sites More sharing options...
hitman6003 Posted April 5, 2007 Share Posted April 5, 2007 Read this page.... http://us.php.net/manual/en/features.file-upload.php Pay special attention to the "Note:" block just below example 38.1 Link to comment https://forums.phpfreaks.com/topic/45715-solved-help-with-upload-script/#findComment-222085 Share on other sites More sharing options...
dragem Posted April 5, 2007 Author Share Posted April 5, 2007 Read this page.... http://us.php.net/manual/en/features.file-upload.php Pay special attention to the "Note:" block just below example 38.1 how it is now it does work i only need something extra Link to comment https://forums.phpfreaks.com/topic/45715-solved-help-with-upload-script/#findComment-222088 Share on other sites More sharing options...
hitman6003 Posted April 5, 2007 Share Posted April 5, 2007 what? Link to comment https://forums.phpfreaks.com/topic/45715-solved-help-with-upload-script/#findComment-222089 Share on other sites More sharing options...
dragem Posted April 5, 2007 Author Share Posted April 5, 2007 the script works at the moment i only want 2 things added to the script so users can give the file a name and discription Link to comment https://forums.phpfreaks.com/topic/45715-solved-help-with-upload-script/#findComment-222094 Share on other sites More sharing options...
dragem Posted April 5, 2007 Author Share Posted April 5, 2007 it wasn't as hard as my first try here's the (final) code <?php session_start(); $id=$_GET["id"]; $title="Fotos Toevoegen" ; include("head.php"); include("open_db.php"); include("securetop.php"); $beschrijving = $_POST["beschrijving"]; $naam =$_POST["naam"]; $queryalbum = "SELECT * FROM albums where albumid = $id "; $resultalbum = mysql_query($queryalbum) or die("Fout bij uitvoeren query"); $linealbum = mysql_fetch_array($resultalbum, MYSQL_ASSOC); error_reporting(E_ALL); $uploadmap = "upload"; $teken="\\"; $map = $uploadmap.$teken.$linealbum["mapnaam"].$teken; // Map waar alles geupload wordt function upload_file($fTmp, $fNew) { if(file_exists($fNew)) { return false; } else { copy($fTmp, $fNew); return true; } } if(Isset($_POST['submit'])) { for($i = 0; $i < count($_FILES['bestand']['name']); $i++) { if(Isset($_FILES['bestand']['name'][$i]) && is_uploaded_file($_FILES['bestand']['tmp_name'][$i])) { if(!upload_file($_FILES['bestand']['tmp_name'][$i], $map.$_FILES['bestand']['name'][$i])) { $error = true; } } } if(IsSet($error)) { echo "Mislukt!"; exit; } else { echo "Gelukt!"; $aantalfoto = count($_FILES['bestand']['name']); $query= ("INSERT INTO fotos (bestandsnaam, albumid, naam, beschrijving) VALUES"); for($tel=0; $tel < $aantalfoto; $tel++){ if ($tel == 0){ $query .= "(\"" . $_FILES['bestand']['name'][$tel] . "\", \"" . $id . "\", \"" . $naam[$tel] . "\", \"" . $beschrijving[$tel] . "\")"; } else { //if($_FILES['bestand']['name'][$tel]==true){ $query .= ",(\"" . $_FILES['bestand']['name'][$tel] . "\", \"" . $id . "\", \"" . $naam[$tel] . "\", \"" . $beschrijving[$tel] . "\")"; //} } } $result = mysql_query($query) or die("Fout bij uitvoeren query1"); } } else { if(IsSet($_POST['aantal'])) { $aantal = $_POST['aantal']; } else { $aantal = 5; } ?> <table border=0> <form enctype="multipart/form-data" action="" method="post"> <tr><td></td><td colsnap="3"><input type="text" name="aantal" value="<?php echo $aantal; ?>" size="1"> <input type="submit" name="aantal_submit" value="Aantal bestanden"> </form></td></tr> <tr><td></td><td colspan="3">zorg dat u zowiezo de eerste invult en upload een foto maar 1 keer</td></tr> <br><br> <form action="" method="post" enctype="multipart/form-data"> <?php for($i = 0; $i < $aantal; $i++) { ?> <tr><td align="right">Naam <?php echo $i + 1; ?>: </td><td><input type="text" name="naam[<?php echo $i; ?>]"></td> <td align="right">Bestand <?php echo $i + 1; ?>: </td><td><input type="file" name="bestand[<?php echo $i; ?>]"></td></tr> <tr><td align="right">Beschrijving <?php echo $i + 1; ?>: </td><td colspan="3"><TEXTAREA NAME="beschrijving[<?php echo $i; ?>]" ROWS="4" COLS="62"></TEXTAREA></td></tr> <tr><td colspan ="4"><br></td></tr> <?php } ?> <tr><td></td><td colspan="3"><input type="submit" name="submit" value="Uploaden"></td></tr> </form> </table> <?php } include("close_db.php"); ?> Link to comment https://forums.phpfreaks.com/topic/45715-solved-help-with-upload-script/#findComment-222184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.