Okay, now that I got that last MySQL thing working okay, another project is causing me trouble. I need to make a file upload script, which I did, but it keeps having more and more errors.
My page to upload looks like this (standard XHTML)
The script to handle this looks like this
It keeps giving me the "Not uploaded file!" message
.
My page to upload looks like this (standard XHTML)
| Code: |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Upload a template!</title> <script type="text/javascript"> function checkfiles() { var fname = document.frm.filename.value; var extstarts = fname.indexOf('.'); var lngth = fname.length; var extension = fname.substring(extstarts, lngth); if(extension != ".pdf" && extension != ".pub" && extension != ".ppt" && extension != ".doc" && extension != ".xls") { alert("This is not an allowed filetype!\n\n" + extension); return false; } if(document.frm.desc.value.length > 600) { alert("This description is too long! They may only be up to 600 characters."); return false; } return true; } </script> </head> <body> <form name="frm" action="upload.php" enctype="multipart/form-data" onsubmit="return checkfiles()"> Your name:<br /> <input type="text" name="name" size="30" maxlength="30" /><br /><br /> A description of your template:<br /> <textarea name="desc" cols="120" rows="4"></textarea><br /><br /> File:<br /> <input type="file" name="filename" size="100" /><br /><br /> <input type="submit" value="Upload!!" /> </form> </body> </html> |
The script to handle this looks like this
| Code: |
| <?php
$fname = $_FILES['filename']['name']; $fpath = $_FILES['filename']['tmp_name']; $fsize = $_FILES['filename']['size']; $name = $_POST['name']; $desc = $_POST['desc']; if($fsize > 1073741824) { die("File size is too big. Only up to 1 Megabyte is allowed."); } $link = mysql_connect("localhost", "teenzine_file", "pass"); mysql_select_db("teenzine_uploads") or die("ERROR<br /><br />$query1<br /><br />".mysql_error()); $query1 = "INSERT INTO uploads(name, filename, description)"."VALUES($name, $fname, $desc)"; mysql_query($query1); $npath = mysql_insert_id(); mkdir($npath); if(!is_uploaded_file($fpath)) { die("Not uploaded file!"); } move_uploaded_file($fpath, $npath) or die("ERROR"); print $fpath; ?> |
It keeps giving me the "Not uploaded file!" message
