steve490 Posted February 4, 2010 Share Posted February 4, 2010 hello there, Can any tell me why this upload code isn't working. What its suppose to do is upload a picture to a server and its id to a database with the users session data. its uploading to the database but not the the server folder heres the code: $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '******'; mysql_select_db($dbname); $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $pic = ($_FILES['uploadedfile']['name']); mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')"); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded to " . $target_path; } else{ echo "There was an error uploading the file, please try again!"; } here's the html <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> cheers in advance Quote Link to comment https://forums.phpfreaks.com/topic/190929-upload-problem-driving-me-crazy/ Share on other sites More sharing options...
$Three3 Posted February 4, 2010 Share Posted February 4, 2010 Okay, it really does not seem to be a code problem to me. It might be a few other things. Try these and see if it helps: 1.) The folder "uploads" might need the permissions to be changed. Try setting them 0755 or 0777. 2.) if you can, depending on your privileges with your server, try putting the uploads directory outside of the web root. So instead of the variable $tagert_path = 'uploads/' it would be written like this: $target_path = '../uploads/' 3.) If you cannot change the path of the uploads directory, try add a forward slash in front of the directory like this: $target_path = '/uploads/' Try those and hopefully one of those work for you. Quote Link to comment https://forums.phpfreaks.com/topic/190929-upload-problem-driving-me-crazy/#findComment-1006862 Share on other sites More sharing options...
PFMaBiSmAd Posted February 4, 2010 Share Posted February 4, 2010 We cannot tell you why the upload is failing because your code has no logic in it to test for any of the possible upload errors and tell you which one it causing the upload to fail. See this recent thread for the things you must test before you attempt to access any of the uploaded file information - http://www.phpfreaks.com/forums/index.php/topic,286370.msg1357855.html#msg1357855 Quote Link to comment https://forums.phpfreaks.com/topic/190929-upload-problem-driving-me-crazy/#findComment-1006867 Share on other sites More sharing options...
steve490 Posted February 4, 2010 Author Share Posted February 4, 2010 Cheers for replying, Im very embarrassed to say that it was not the code after all but the uploads folder on the server not refreshing, which is my fault for not checking the most obvious thing first. sorry for wasting your time Quote Link to comment https://forums.phpfreaks.com/topic/190929-upload-problem-driving-me-crazy/#findComment-1006957 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.