jera Posted March 26, 2007 Share Posted March 26, 2007 Oke here we go, I have a script to update images. Now i'm looking for a script to change the upload files. (So i put a file in the database, next week i want a other image in the database.) I lookt at a lot php sites but i only find upload scrips. So i need to make it my self: <? //######################################################################### //######### Vul hieronder de waardes in voor het upload script ############ //######################################################################### $server = "localhost"; //de server waarop de database is geinstaleerd $gebruiker = "naam"; //de gebruikersnaam van de database $password = "ww"; //het wachtwoord voor de database horende bij de ingevulde gebruiker $database = "db"; //de naam van de database $toegestaan = array('jpg', 'gif', 'png', 'bmp'); //vul in deze array de toegestane extensies in gescheiden door een comma $maxfilesize = 2; //vul hier de toegestane filesize in MB's in $maxwidth = 800; //de maximale breedte van het geuploade bestand $maxheight = 600; //de maximale hoogte van het geuploade bestand $directory = "../munten1/"; //de map waar de upload in moeten komen, inclusief slashes $tabelnaam = "uploads"; //de naam van de tabel waar de upload in moet komen //######################################################################## //################ Verander onder deze lijn niets ######################## //######################################################################## ?> <html> <head> <title>Upload Script:</title> </head> <body bgcolor="#99CCFF"> <?php //verbinding maken met de database: mysql_connect($server, $gebruiker, $password) or die ("Geen verbinding met de server"); mysql_select_db($database) or die ("De database kon niet gevonden worden"); //code alleen uitvoeren wanneer er op submit is geklikt: if(isset($_POST['submit'])) { if($_POST['naam'] == "") { echo("<script language=\"javascript\">alert('U bent vergeten de naam in te vullen');</script>"); }else{ if($_POST['onderwerp'] == "") { echo("<script language=\"javascript\">alert('U bent vergeten een onderwerp in te vullen');</script>"); }else{ if($_FILES['file']['name'] == "") { echo("<script language=\"javascript\">alert('U bent vergeten een file te selecteren');</script>"); }else{ //extensies controleren: $extensie = explode(".", $_FILES['file']['name']); $extcount = count($toegestaan); $extcount2 = count($toegestaan); for($a=0;$a<$extcount;$a++) { if(strtolower($extensie[1]) == $toegestaan[$a]) { $extok = true; $a = count($toegestaan); }else{ $extok = false; } } if($extok == false) { echo("<script language=\"javascript\">alert('Deze extensie is niet geldig. Geldige extensies zijn:\\n"); for($b=0;$b<$extcount;$b++) { $extup = strtoupper($toegestaan[$b]); if($b == $extcount - 1) { echo("$extup"); }else{ echo("$extup, "); } } echo("');</script>"); }else{ //bestandsgrootte controleren: $filesize = $_FILES['file']['size']; $filesize2 = ("".ROUND($filesize / 1024, 1)." KB"); if($filesize > 1024) { $filesize2 = ("".ROUND($filesize2 / 1024, 1)." MB"); } if($filesize > 1073741824) { $filesize2 = ("".ROUND($filesize2 / 1024 / 1024 / 1024, 1)." GB"); } $maxfilesize2 = $maxfilesize * 1024 * 1024; if($_FILES['file']['size'] > $maxfilesize2) { echo("<script language=\"javascript\">alert('Dit bestand is te groot voor de upload\\nToegstaan: $maxfilesize MB');</script>"); }else{ //op dubbele files controleren: $filenaam = $_FILES['file']['name']; if(file_exists("$directory$filenaam")) { echo("<script language=\"javascript\">alert('De bestandnaam ($filenaam) is al in gebruik');</script>"); }else{ //image size controleren: $size = getimagesize($_FILES['file']['tmp_name']); $width = $size[0]; $height = $size[1]; if($width > $maxwidth || $height > $maxheight) { echo("<script language=\"javascript\">alert('Het formaat van dit bestand is niet correct.\\nMag max zijn: $maxwidth x $maxheight');</script>"); }else{ //Wanneer alles correct is, file uploaden: $pad = $directory; if(isset($_POST['submit'])) { $query = "INSERT INTO $tabelnaam(naam, datum, comment, filenaam) VALUES('".$_POST['naam']."', now(), '".$_POST['onderwerp']."', '$pad$filenaam')"; $result = mysql_query($query); copy($file, "$pad".$_FILES['file']['name'].""); echo("<center><font color=red>File uploaded...</font></center>"); } } } } } } } } } //Het formulier: //string opbouwen voor in help alertbox. $string = ("Maximale Grootte: $maxfilesize MB\\nFormaat: $maxwidth x $maxheight\\nExtensies:"); for($c=0;$c<$extcount2;$c++) { $extup2 = strtoupper($toegestaan[$c]); if($c == $extcount2 - 1 ) { $string .=("$extup2\\n"); }else{ $string .=("$extup2, "); } } $string .=("Geen dubbele bestandsnamen."); echo("<center><table border=0 style=\"border-style: double; border-color=red\"> <form action=$_SERVER[php_SELF] method=POST name=\"uploadform\" enctype=\"multipart/form-data\"><tr> <td>Naam:         <Input type=textbox name=naam size=45></td></tr><tr> <td>Onderwerp: <Input type=textbox name=onderwerp size=45></td></tr><tr> <td><input type=file name=file size=42></td></tr><tr> <td><table width=100%><tr><td width=33%> </td><td align=center width=33%><input type=submit name=submit value=\"Upload file\"></td><td align=right>"); ?><a href="#" onCLick="alert('Voor het uploaden van het bestand gelden de volgende regels:\n<? echo($string); ?>');">Help</a> <?php echo("</td></tr></table></td></tr> </form></td></tr></table></center>"); ?> </body> </html>. Oke i edit it this: At the top is set $id=1; next where we submit the stuff i made it like this: //Wanneer alles correct is, file uploaden: $pad = $directory; if($_SERVER['REQUEST_METHOD'] == 'submit') { if(!is_numeric($_POST['id'])) die("fout ID"); $query = " UPDATE $tabelnaam SET title = '".mysql_real_excape_string($_POST['title'])."', description = '".mysql_real_excape_string($_POST['description'])."', albumid = '".mysql_real_excape_string($_POST['album'])."' WHERE id = ".$id.""; $result = mysql_query($query); Only now he won't upload nore while he change stuff in the database/... WHELP Link to comment https://forums.phpfreaks.com/topic/44336-edit-image-data-in-sql/ Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 We need a clearer description of your problem, posting only the relevent code and exactly what you expect it to do, along with a description of what it is doing. Link to comment https://forums.phpfreaks.com/topic/44336-edit-image-data-in-sql/#findComment-215318 Share on other sites More sharing options...
jera Posted March 26, 2007 Author Share Posted March 26, 2007 Ow sorry i tought i was clear... But oke again. I have the scrip what you see at the top. This updates image to a map in de website and puts some information from it in my sql database (This works great!) But whe i have update a image, i sometimes want to change it. So i need a script that takes the id from my sql database and edit the information in that row. (Deleting the image from the folder is not a isseu) So I lookt everywhere but i only find upload scrips. So i tough oke we take my upload scrip and edit this. So i did, I put in the $ id. So we know with id we want to change. And i change de submit part. See top post. But know it doesn't upload the images annymore.. And it doesn't change the text in the sql database.... (Understand it?) Link to comment https://forums.phpfreaks.com/topic/44336-edit-image-data-in-sql/#findComment-215325 Share on other sites More sharing options...
trq Posted March 26, 2007 Share Posted March 26, 2007 Sor, I fin it ard to pick u speak. Link to comment https://forums.phpfreaks.com/topic/44336-edit-image-data-in-sql/#findComment-215328 Share on other sites More sharing options...
jera Posted March 26, 2007 Author Share Posted March 26, 2007 yeah sorry i'm dutch and i'm a dislect (Word blind) So it is hard for me to explain it al... Link to comment https://forums.phpfreaks.com/topic/44336-edit-image-data-in-sql/#findComment-215329 Share on other sites More sharing options...
jera Posted March 27, 2007 Author Share Posted March 27, 2007 can someboddy help me Link to comment https://forums.phpfreaks.com/topic/44336-edit-image-data-in-sql/#findComment-215872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.