podja Posted July 3, 2007 Share Posted July 3, 2007 Hey, I have been trying to integrate a file upload script into a script that inserts stuff into the database. I've been trying all day and don't see why it wont work. It works fine by itself, but when added to the other script it wont work. Heres the full script I'm using (Its a bit long but I'm sure you can help!) Heres the form I am using: <!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>Untitled Document</title> </head> <body> <h1>Update FunVid.net</h1> <p>Fill in the forms below to update FunVid.net</p> <?php if(isset($_POST['submit'])) { include('insert.php'); } ?> <fieldset> <form name="update01" method="post" enctype="multipart/form-data"> <label for="title">Title:</label><br /> <input type="text" name="title" id="title" tabindex="1" value="<?php if(isset($title)) {echo $title;} ?>" /><br /> <label for="desc">Video Description</label><br /> <textarea name="desc" id="desc" rows="10" cols="100" tabindex="2"><?php if(isset($desc)) {echo $desc;} ?></textarea><br /> <label for="embed">YouTube Embed Code (Will be validated)</label><br /> <textarea name="embed" id="embed" rows="10" cols="100" tabindex="3"><?php if(isset($embed)) {echo $embed;} ?></textarea><br /> <label for="img">Image To Upload</label><br /> <input type="file" name="imgfile" id="imgfile" tabindex="4" /> <br /> <input type="submit" name="submit" id="submit" value="Update FunVid.net!" /> </form> </fieldset> </body> </html> And heres the PHP I am using: <?php // Insert Code | Code To Insert Stuff Into Database include('connect.php'); // Get The Values From The Form $title = $_POST['title']; $desc = $_POST['desc']; $embed = $_POST['embed']; $embed = stripslashes($embed); $date = date("d/m/y"); // Image Upload Variable // Create matches array for Youtube ccde validator $matches = array(); // create the errors array $errors = array(); // Validate the title input if(strlen($title) < 5) { $errors[] = 'Your Title Needs To Be A Bit Longer Than That!'; } // Validate the description input if(strlen($desc) < 20) { $errors[] = 'Your Description Needs To Be A Bit Longer Than That!'; } // Validate the embed input if(strlen($embed) < 30) { $errors[] = 'You Need To Embed Your YouTube Video!'; } // If no errors if(empty($errors)) { // The code to validate youtube input $i = strpos($input,'youtube.com/v/'); $length = strlen('youtube.com/v/'); while ( $i !== FALSE) { $l = strpos($input,'"',$i); if ($l !== FALSE) { $matches[] = substr($input,$i+$length,$l-$i-$length); } $i = strpos($input,'youtube.com/v/',$l); } $moviecode = $matches[0]; $embed = "<object type=\"application/x-shockwave-flash\" data=\"http://www.youtube.com/v/$moviecode\" width=\"425\" height=\"350\"><param name=\"movie\" value=\"http://www.youtube.com/v/$moviecode\" /></object>"; $uploadpath = "uploads/"; $uploadpath = $uploadpath . basename( $_FILES['imgfile']['name']); move_uploaded_file($_FILES['imgfile']['tmp_name'], $uploadpath); $query = "INSERT INTO `updates` (`title`, `desc`, `embed`, `img`, `date`) VALUES ('$title', '$desc', '$embed', '$img', '$date')"; $exe = mysql_query($query); } else { foreach($errors as $error) { echo "<p class=\"errors\">$error</p>"; } } ?> I dont get any errors and everything inserts into the database fine. Its just the image wont upload. Cheers. P.S - I have definately set the permissions to 777 before you ask, hehe. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 3, 2007 Share Posted July 3, 2007 Where do you define $img? (You use it in the query, but I don't see it used elsewhere.) Quote Link to comment Share on other sites More sharing options...
podja Posted July 3, 2007 Author Share Posted July 3, 2007 O must have deleted that by mistake. That has nothing to do with the file upload at this point though. Quote Link to comment Share on other sites More sharing options...
podja Posted July 3, 2007 Author Share Posted July 3, 2007 Anyone? I know your all geniuses Someone must have an answer! Quote Link to comment Share on other sites More sharing options...
ikscovski Posted July 3, 2007 Share Posted July 3, 2007 not sure but iv noticed that u have left out the action statement in ur form tags. yours - <form name="update01" method="post" enctype="multipart/form-data"> mine - <form action='movieReg.php' method='post' enctype='multipart/form-data'> also i dont c an indication as to the file type/ extension that u r trying to upload. eg. if (($_FILES['file']['type'] == 'image/bmp'||'image/jpeg') && ($_FILES['file']['size'] < 50000)) Quote Link to comment Share on other sites More sharing options...
fusioneko Posted July 3, 2007 Share Posted July 3, 2007 Anyone? I know your all geniuses Someone must have an answer! We aren't all genuises. as much as I can say is. If you havent checked already. Try to compare with other file upload scripts to yours and see how they work to grasp the concept how yours should work in a similiar way. I can't really find anything wrong. besides this. <form name="update01" method="post" enctype="multipart/form-data"> <label for="title">Title:</label><br /> <input type="text" name="title" id="title" tabindex="1" value="<?php if(isset($title)) {echo $title;} ?>" /><br /> <label for="desc">Video Description</label><br /> <textarea name="desc" id="desc" rows="10" cols="100" tabindex="2"><?php if(isset($desc)) {echo $desc;} ?></textarea><br /> <label for="embed">YouTube Embed Code (Will be validated)</label><br /> <textarea name="embed" id="embed" rows="10" cols="100" tabindex="3"><?php if(isset($embed)) {echo $embed;} ?></textarea><br /> <label for="img">Image To Upload</label><br /> <input type="file" name="imgfile" id="imgfile" tabindex="4" /> <br /> <input type="submit" name="submit" id="submit" value="Update FunVid.net!" /> Unless the stored variables come from insert.php Of course I know nothing about file uploads. Buuut Im just browsing along. 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.