plastik77 Posted July 12, 2007 Share Posted July 12, 2007 Hi - just a quick query (couldn't find an answer elsewhere on the forum) - I've set up a form for uploading multiple images and I am writing the urls to a database, which is queried and outputs the images on a web page. This works fine, however, I also want to add alt/title text for each image upload but can't quite seem to get it working. I'm pretty new to PHP so my knowledge of how to use arrays is fairly limited. If anyone could offer any help that would be appreciated. Code is as follows. //html form <form method="post" action="addimgck.php" id="newsForm" enctype="multipart/form-data"> <label for="user">Title</label> <input type="text" name="title" value="" /><br /> <label for="comments">Content:</label> <textarea name="story"></textarea><br/> <p align="justify"> Upload images: <span id="alttext">Image Description</span><br/><br/> <input type="file" name="images[]" size="40"><input type="text" name="alt[]" value="" /><br/> <input type="file" name="images[]" size="40"><input type="text" name="alt[]" value="" /><br/> <input type="file" name="images[]" size="40"><input type="text" name="alt[]" value="" /><br/> <input type="file" name="images[]" size="40"><input type="text" name="alt[]" value="" /><br/> </p> <input type="submit" name="Submit" id="submitbutton" value="Submit" /> //addimgck.php script <?php include("functions.php"); dbconnect(); //get inputs $title = $_POST['title']; $story = $_POST['story']; //insert story into dbs $insert = mysql_query("insert into news (title,story) values ('$title','$story')"); if(!$insert) echo "insert problem"; $query = mysql_query("select id from news where title = '$title' and story = '$story'"); if(!query) echo "no data found"; else { $row = mysql_fetch_array($query); $id = $row['id']; } //insert corresponding images into dbs while(list($key,$value) = each($_FILES[images][name])) { if(!empty($value)) { $filename = $value; //$alt = $_POST[alt][name]; $add = "news/$filename"; //echo $_FILES[images][type][$key]; // echo "<br>"; copy($_FILES[images][tmp_name][$key], $add); chmod("$add",0777); $insert_img = mysql_query("insert into image (url,alt,news_id) values ('$filename','$alt',$id) "); if(!insert_img) echo "didn't insert images"; } } header("location:newsbackup2.php"); // direct to news page ?> 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.