Valentinez Posted January 12, 2010 Share Posted January 12, 2010 I have no idea whats wrong. Error code not working. Here.s the entire page, some things changed for security. <?php // Connect to database $errmsg = ""; if (! @mysql_connect("host","login","pass")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("database"); // First run ONLY - need to create table by uncommenting this // Or with silent @ we can let it fail every sunsequent time ;-) /* $q = < < <CREATE create table pix ( pid int primary key not null auto_increment, title text, imgdata longblob) CREATE; */ @mysql_query($q); // Insert any new image into database if ($_REQUEST[completed] == 1) { // Need to add - check for large upload. Otherwise the code // will just duplicate old file ;-) // ALSO - note that latest.img must be public write and in a // live appliaction should be in another (safe!) directory. move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img"))); if (strlen($instr) < 149000) { mysql_query ("insert into pix (title, imgdata) values (\"". $_REQUEST[whatsit]. "\", \"". $image. "\")"); } else { $errmsg = "Too large!"; } } // Find out about latest image $gotten = @mysql_query("select * from pix order by pid desc limit 1"); if ($row = @mysql_fetch_assoc($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata]; } else { $errmsg = "There are no Members yet."; $title = "No database image available."; } // If this is the image request, send out the image if ($_REQUEST[gim] == 1) { header("Content-type: image/jpeg"); print $bytes; exit (); } ?> <html><head> <title>Cult Signup!</title> <script type="text/javascript"> <!--// function validateFileExtension(fld) { if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(fld.value)) { alert("Invalid image file type."); fld.form.reset(); fld.focus(); return false; } return true; } function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } } } function validate_form(thisform) { with (thisform) { if (validate_required(whatsit,"Must have a Name or Alias")==false) {whatsit.focus();return false;} } } //--> </script> </head> <body bgcolor=white><center><h2>Here's the latest Member!</h2></center> <font color=red><?= $errmsg ?></font> <center><img src=?gim=1 width=144><br /> <b><?= $title ?></b></center> <hr> <h2>Please Upload Your Picture or Avatar, and your Name or Alias.</h2> <form enctype="multipart/form-data" method="post" onsubmit="return (validateFileExtension(this.imagefile) && validate_form(this))"> <input type="hidden" name="MAX_FILE_SIZE" value="150000"> <input type="hidden" name="completed" value="1"> Please choose an image to upload: <input type="file" name="imagefile" onchange="return validateFileExtension(this)"><br /> Name or Alias: <input name="whatsit"><br /> <input type="submit"></form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/188267-error/ Share on other sites More sharing options...
mikesta707 Posted January 12, 2010 Share Posted January 12, 2010 the error message and line number would help Quote Link to comment https://forums.phpfreaks.com/topic/188267-error/#findComment-993895 Share on other sites More sharing options...
Valentinez Posted January 13, 2010 Author Share Posted January 13, 2010 There are no error messages. It just doesn't work the way it's supposed to. It's supposed to stop., and spit out an error if the file size for the picture is to big. It doesn't. if ($_REQUEST[completed] == 1) { // Need to add - check for large upload. Otherwise the code // will just duplicate old file ;-) // ALSO - note that latest.img must be public write and in a // live appliaction should be in another (safe!) directory. move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img"))); if (strlen($instr) < 149000) { mysql_query ("insert into pix (title, imgdata) values (\"". $_REQUEST[whatsit]. "\", \"". $image. "\")"); } else { $errmsg = "Too large!"; } } Quote Link to comment https://forums.phpfreaks.com/topic/188267-error/#findComment-993955 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.