daebat Posted December 29, 2010 Share Posted December 29, 2010 I'm having some trouble with an image upload form. I have a few instances of this code that works in other areas of my site so I'm pretty sure there is just something small that I'm missing: The Form: <? include("../include/session.php"); ?> <html> <head> <title>Template Configuration</title> <link rel="stylesheet" type="text/css" href="../css/backend.css"> </head> <body> <? if($session->logged_in){ $data = mysql_query("SELECT * FROM template WHERE id = '1'") or die(mysql_error()); while($info = mysql_fetch_array( $data )) { echo " <h1 style='text-align:center;'>Template Configuration</h1> <div id='textedit'> <form method='post' action='templateprocess.php' enctype='multipart/form-data'> <table> <tr><td><h2>Header Image</h2></td></tr> <tr><td colspan='2' style='text-align:center'><img src='../upload/template/".$info['headerimg'] ."'><br /><br /></tr></td> <tr> <td>Image Upload:</td> <td> <input type='file' name='headerimg'> </td> </tr> </table <input type='hidden' name='id' value='1'> <input TYPE='submit' name='upload' title='Add data to the Database' value='Submit'/> </form> <a href='../main.php'><img src='../images/backButton.jpg'></a> </div> "; } } else{ echo "[<a href='../main.php'>Please Login</a>] "; } ?> </body> </html> The Processor: <? include("../include/session.php"); ?> <html> <head> <title>Template Configuration</title> <link rel="stylesheet" type="text/css" href="../css/backend.css"> </head> <body> <div id='process'> <? if($session->logged_in){ $target = "/path/to/folder/upload/template/"; if ($headerimg != ''){ $headerimg = ($_FILES['headerimg']['name']); foreach($_FILES as $file) { move_uploaded_file($file['tmp_name'], $target . $file['name']); } mysql_query("UPDATE template SET headerimg ='$headerimg' WHERE id ='1'"); } ?> <p>Update Successful... <a href="../main.php">click here</a> to return to the administration area.</p> <?php } else{ echo "[<a href='../main.php'>Please Login</a>] "; } ?> </div> </body> </html> My database has a table named 'template' with two fields of 'id' and 'headerimg'. I have inserted into the table (id) '1' and (headerimg) 'header-image.png' and is reading this as a preview above. I can't, however, get the 'headerimg' field to update and the image never uploads into my template folder. Quote Link to comment Share on other sites More sharing options...
requinix Posted December 29, 2010 Share Posted December 29, 2010 Does the upload directory have the correct permissions set? Quote Link to comment Share on other sites More sharing options...
daebat Posted December 29, 2010 Author Share Posted December 29, 2010 While I am working on this it is set to 777. I'm also not getting anything written to the database so it's a double oops somewhere. Quote Link to comment Share on other sites More sharing options...
litebearer Posted December 29, 2010 Share Posted December 29, 2010 are you getting any error messages? simple trick to see where code goes, is to place echo "here"; exit(); at the point(s) where you think it should be reaching ie is it entering your IF statements or bypassing them Quote Link to comment Share on other sites More sharing options...
daebat Posted December 29, 2010 Author Share Posted December 29, 2010 argg I just rewrote all of my code in a little different way and it still does the same thing. I'm wondering if somehow I set up the database wrong? It is just an int storing the ID and varchar storing a 250 char image name... Quote Link to comment Share on other sites More sharing options...
requinix Posted December 29, 2010 Share Posted December 29, 2010 ...Uh... if ($headerimg != ''){ $headerimg = ($_FILES['headerimg']['name']); Quote Link to comment Share on other sites More sharing options...
daebat Posted December 29, 2010 Author Share Posted December 29, 2010 sorry I'm not very good with PHP yet. what's wrong with that code? I have the same code working in another area of the cms. Here is a working version: $ordering=$_POST['ordering']; $title=$_POST['title']; $id=$_GET['id']; if ($image != ''){ $image = ($_FILES['image']['name']); foreach($_FILES as $file) { move_uploaded_file($file['tmp_name'], $target . $file['name']); } mysql_query("UPDATE tablename SET image ='$image' WHERE id ='$id'"); } if ($thumb != ''){ $thumb = ($_FILES['thumb']['name']); foreach($_FILES as $file) { move_uploaded_file($file['tmp_name'], $target . $file['name']); } mysql_query("UPDATE tablename SET thumb ='$thumb' WHERE id ='$id'"); } mysql_query("UPDATE tablename SET ordering = '$ordering', title = '$title' WHERE id ='$id' "); 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.