bradkenyon Posted May 1, 2008 Share Posted May 1, 2008 i am trying to upload a file to a directory on my server, then post the filename into the database for future reference. for some reason the file won't upload, nor will it post the filename into the db. i've done this before, but it was done before by having the action="" within the form tag pointing to another page w/ the appropriate code for getting the form results, but i want it to do a php self post, but that is the problem i'm running into w/ getting that file to upload. here is the code. any help is appreciated, thanks! if(!$_POST) { ?> <div class="details"> <form enctype="multipart/form-data" method="post" action="?mode=add"> <? print '<h3>Headline/Subject</h3>'; print '<input type="text" name="subj" size="60">'; print '<h3>Body</h3>'; print '<textarea name="body" cols="70" rows="14"></textarea>'; /* print '<h3>Image URL</h3>'; print '<input type="text" name="imgurl" size="80">'; */ print '<h3>More Info URL</h3>'; print '<input type="text" name="moreurl" size="80">'; print '<h3>Date</h3>'; print '<input type="text" name="tstamp" value="'.date("Y-m-d H:i:s",time()).'" size="20">'; print '<h3>Image Upload</h3> <input type="file" name="uploaded"> <small>(optional)</small><p>'; print '<input type="Submit" value="Submit" name="Submit"> <a href="/cms/">Cancel</a> </form>'; } else { //$id=$HTTP_POST_VARS['id']; $subj=addslashes($HTTP_POST_VARS['subj']); $body=addslashes(htmlspecialchars($HTTP_POST_VARS['body'])); //$imgurl=$HTTP_POST_VARS['uploaded']; $moreurl=$HTTP_POST_VARS['moreurl']; $tstamp=$HTTP_POST_VARS['tstamp']; $filename=$_FILES['uploaded']['name']; if(!$filename == '') { $target = "/web/images/news/"; $target = $target . basename( $_FILES['uploaded']['name']); $ok=1; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { //echo "The file ".basename( $_FILES['uploaded']['name'])." has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } mysql_query("INSERT INTO news (subj, body, imgurl, moreurl, tstamp) VALUES('$subj', '$body', '$filename', '$moreurl', '$tstamp')") or die(mysql_error()); include('newslist.php'); } ?> Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted May 1, 2008 Author Share Posted May 1, 2008 SOLVED Quote Link to comment Share on other sites More sharing options...
947740 Posted May 1, 2008 Share Posted May 1, 2008 Hit the "Topic Solved" link in the bottom left-hand corner. Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted May 1, 2008 Author Share Posted May 1, 2008 thanks, i always wondered where that button was. duh. Quote Link to comment 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.