jorre13 Posted March 21, 2007 Share Posted March 21, 2007 hey, I have make a form with some text which must be saved into mysql and a file who must upload to a directory. It work for text or for the file but it seems it isn't possible to do it together. this is my code addpowerpoint.php <?php require("../../../../includes/connect.php"); // verbinding met de database maken ?> <html> <head> <title>add powerpoint</title> <LINK href="../../../Haco.css" type=text/css rel=stylesheet> </head> <body> <center> <?php // als het formulier nog niet is ingevuld if(!isset($_POST['add'])) { ?> <table width="600" class="Tabel_1"> <tr> <td align="center"> <form action="addpowerpoint.php" method="post" ENCTYPE="multipart/form-data"> <table> <tr> <td>title: </td> <td> <input type="text" name="title" size="40" maxlength="20" /></td> </tr> <tr> <td>description: </td> <td> <input type="text" name="description" size="40" maxlength="180" /></td> </tr> <tr> <td>file: </td> <td> <input type="file" name="file" size="40" maxlength="40" /></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" name="add" value="add" /></td> </tr> </table> </form> </td> </tr> <tr> <td align="center"><a href="powerpoints.php">back to powerpointlist</a></td> </tr> </table> <?php // formulier gepost, kijk of alle velden ook daadwerkelijk zijn ingevuld } elseif(trim($_POST['title']) <> "" && trim($_POST['description']) <> "" && trim($_POST['file']) <> "") { // formulier ingevuld - kijk eerst of de title al bestaat $title = $_POST['title']; $description = $_POST['description']; //$filename = $_FILES['file']['name']; $filename = "test"; //$filesize= $_FILES['file']['size']; $filesize= "15"; $categorie = "shears"; $res = mysql_query("SELECT * FROM powerpoints WHERE title='".$title."'") or die(mysql_error()); if(mysql_num_rows($res) == 0) { // geen resultaten - dit is wat we willen mysql_query("INSERT INTO powerpoints (title, description, filename, filesize, categorie) VALUES ('".$title."', '".$description."' , '".$filename."', '".$filesize."', '".$categorie."')") or die(mysql_error()); require("../../../../includes/disconnect.php"); //verbinding sluiten //require("upload.php"); //file uploaden }else{// title bestaat al ?> <table width="600" class="Tabel_1"> <tr> <td align="center"> The title you have choosen already excist.<br /> <a href="javascript:history.back()">Press back and enter a new title.</a><br/> </td> </tr> </table> <?php } // geef melding weer ?> <table width="600" class="Tabel_1"> <tr> <td align="center"> Your powerpoint is added<br /> <a href="addpowerpoint.php"> add another one</a><br /> <a href="powerpoints.php"> back to powerpointlist</a> </td> </tr> </table> <?php } ?> </center> </body> </html> upload.php <?php error_reporting(E_ALL ^ E_NOTICE); // ============== // Configuration // ============== $uploaddir = "uploads/"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777! $allowed_ext = "txt, ppt, pps"; // These are the allowed extensions of the files that are uploaded $max_size = "150000000"; // 150000000 is the same as +/-150Mb $max_height = "100"; // This is in pixels - Leave this field empty if you don't want to upload images $max_width = "100"; // This is in pixels - Leave this field empty if you don't want to upload images // Check Entension $extension = pathinfo($_FILES['file']['name']); $extension = $extension[extension]; $allowed_paths = explode(", ", $allowed_ext); for($i = 0; $i < count($allowed_paths); $i++) { if ($allowed_paths[$i] == "$extension") { $ok = "1"; } } // Check File Size if ($ok == "1") { if($_FILES['file']['size'] > $max_size) { echo "<html>"; echo "<head>"; echo "<title>incorrect upload</title>"; echo "<LINK href='../../../Haco.css' type=text/css rel=stylesheet>"; echo "</head>"; echo "<body>"; echo "<center>"; echo "<table width='600' class='Tabel_1'> "; echo "<tr>"; echo "<td align='center'>"; echo "File size is too big!(max 150Mb)<br/>"; echo "<a href='javascript:history.back()'>Press back and enter a new powerpoint.</a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</center>"; echo "</body>"; echo "</html>"; exit; } // Check Height & Width if ($max_width && $max_height) { list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']); if($width > $max_width || $height > $max_height) { echo "<html>"; echo "<head>"; echo "<title>incorrect upload</title>"; echo "<LINK href='../../../Haco.css' type=text/css rel=stylesheet>"; echo "</head>"; echo "<body>"; echo "<center>"; echo "<table width='600' class='Tabel_1'> "; echo "<tr>"; echo "<td align='center'>"; echo "File height and/or width are too big!<br/>"; echo "<a href='javascript:history.back()'>Press back and enter a new powerpoint.</a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</center>"; echo "</body>"; echo "</html>"; exit; } } // The Upload Part if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']); } echo "<html>"; echo "<head>"; echo "<title>correct upload</title>"; echo "<LINK href='../../../Haco.css' type=text/css rel=stylesheet>"; echo "</head>"; echo "<body>"; echo "<center>"; echo "<table width='600' class='Tabel_1'> "; echo "<tr>"; echo "<td align='center'>"; echo "Your file has been uploaded successfully!<br/>"; echo "<a href='addpowerpoint.php'>add another powerpoint</a><br/>"; echo "<a href='powerpoints.php'>back to powerpointlist</a><br/>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</center>"; echo "</body>"; echo "</html>"; //print "<br>size: "; //print $_FILES['file']['size']; //print "<br>name: "; //print $_FILES['file']['name']; } else { echo "<html>"; echo "<head>"; echo "<title>incorrect upload</title>"; echo "<LINK href='../../../Haco.css' type=text/css rel=stylesheet>"; echo "</head>"; echo "<body>"; echo "<center>"; echo "<table width='600' class='Tabel_1'> "; echo "<tr>"; echo "<td align='center'>"; echo "Incorrect file extension!<br/>"; echo "<a href='javascript:history.back()'>Press back and enter a new powerpoint.</a>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</center>"; echo "</body>"; echo "</html>"; } ?> Link to comment https://forums.phpfreaks.com/topic/43655-upload-problem/ Share on other sites More sharing options...
jorre13 Posted March 21, 2007 Author Share Posted March 21, 2007 i have changed a little bit: //require("upload.php"); //file uploaden changed into require("upload.php"); //file uploaden and now i get following errors: Notice: Undefined index: file in C:\Site\HSC\frameset\solutions\shears\powerpoints\upload.php on line 16 Notice: Use of undefined constant extension - assumed 'extension' in C:\Site\HSC\frameset\solutions\shears\powerpoints\upload.php on line 17 Notice: Undefined index: extension in C:\Site\HSC\frameset\solutions\shears\powerpoints\upload.php on line 17 Notice: Undefined variable: ok in C:\Site\HSC\frameset\solutions\shears\powerpoints\upload.php on line 26 Link to comment https://forums.phpfreaks.com/topic/43655-upload-problem/#findComment-211931 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.