doddsey_65 Posted April 6, 2010 Share Posted April 6, 2010 the following is a script that is already in use for a different part of my site to upload a profile picture to a directory and then send the path of it to the database. Hoever i have copied the script and tried to use it in a different way. Same premise but a bit more information being sent with it. When I click upload it says there was an error uploading. Is this because i have done something wrong? or is it because i am inserting info into the database and sending the file to the directory? <?php ob_start(); $uploadDir2 = 'tutcovers/'; if(isset($_POST['upload_btn3'])) { $fileName2 = $_FILES['userfile3']['name']; $tmpName2 = $_FILES['userfile3']['tmp_name']; $filePath2 = $uploadDir2 . $fileName2; $result = move_uploaded_file($tmpName2, $filePath2); if (!$result) { echo "Error uploading file"; exit; } if(!get_magic_quotes_gpc()) { $filePath2 = addslashes($filePath2); } $sql = ("INSERT INTO tutorials (name, description, username, fullname, link, path, category, length) VALUES ('".$_POST['name']."', '".$_POST['description']."', '".$_POST['username']."', '".$_POST['fullname']."', '".$_POST['embedd']."', '".$filepath2."', '".$_POST['category']."', '".$_POST['vidlength']."')"); $result = mysql_query($sql, $db); } echo ' <div id="page"> <div id="content"> <div class="post"> <p class="meta">Your image has been successfully uploaded</p> <div class="entry">'; echo 'Your tutorial has been successfully uploaded. Click <a href=myaccount.php>here</a> to go back. </div></div></div>'; include('footer.php'); ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/197701-uploading-error/ Share on other sites More sharing options...
anupamsaha Posted April 6, 2010 Share Posted April 6, 2010 Hi, Is the folder "tutcovers" has write permission? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/197701-uploading-error/#findComment-1037645 Share on other sites More sharing options...
doddsey_65 Posted April 11, 2010 Author Share Posted April 11, 2010 yes it has the correct permissions, basically everything is the same as the other upload script I am using, but this one is sending more than just the image path to the database. Quote Link to comment https://forums.phpfreaks.com/topic/197701-uploading-error/#findComment-1040095 Share on other sites More sharing options...
the182guy Posted April 11, 2010 Share Posted April 11, 2010 $filePath2 is being used in move_uploaded_file() but it's not being set anywhere. That's the problem. Should you be using $uploadDir2? Like $result = move_uploaded_file($tmpName2, $uploadDir2 . $fileName2); Quote Link to comment https://forums.phpfreaks.com/topic/197701-uploading-error/#findComment-1040105 Share on other sites More sharing options...
doddsey_65 Posted April 11, 2010 Author Share Posted April 11, 2010 $filepath2 has been set : $filePath2 = $uploadDir2 . $fileName2; I have kept everything the same as is in the other upload script i am using(in which everything works) the only difference is that the one that works only uploads an image to the server and sends the path to the database while with this one I am trying to add some field information aswell as the image. Quote Link to comment https://forums.phpfreaks.com/topic/197701-uploading-error/#findComment-1040162 Share on other sites More sharing options...
the182guy Posted April 12, 2010 Share Posted April 12, 2010 Have you double checked that the HTML file input is named userfile3? Have a look what files are present with print_r($_FILES); See if $_FILES['userfile3']['error'] is not 0. Quote Link to comment https://forums.phpfreaks.com/topic/197701-uploading-error/#findComment-1040487 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.