Jump to content

[SOLVED] Help with upload script


dragem

Recommended Posts

ok i need help with a script

right now i got a script that uploads and put some data in the database

 

printjt8.png

 

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
Share on other sites

it wasn't as hard as my first try

piceo2.jpg

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.