sandbudd Posted November 21, 2009 Share Posted November 21, 2009 writes to the database fine but does not upload the image? I get no errors...sorry for the spacing. <?php //This is the directory where images will be saved $target = 'images/'; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $pic=($_FILES['photo']['name']); // Connects to your Database mysql_connect("", "", "") or die(mysql_error()) ; mysql_select_db("") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `alabama` VALUES ('$pic')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ". basename( $_FILES['photo']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/ Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 I know this is a simple code but can't see the error? Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962660 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 Try this and see what happens: <?php //This is the directory where images will be saved $target = 'images/'.$_FILES['photo']['name']; //This gets all the other information from the form $pic= $_FILES['photo']['name']; // Connects to your Database mysql_connect("", "", "") or die(mysql_error()) ; mysql_select_db("") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `alabama` VALUES ('$pic')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "The file ".$_FILES['photo']['name']. " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962664 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 Also please note that are two main security flaws in your script. 1: You're not checking to see if the filetype is acceptable, which means that any old file could be uploaded to your server. What if somebody uploaded a .php file? They'd be able to upload it to your server and then execute it. 2: You're not using the function is_uploaded_file(). is_uploaded_file() makes sure that the file in question has actually been uploaded. Otherwise, an attacker could give you the file location of a sensitive file outside your root... only to have that sensitive file copied to a publicly viewable location. Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962671 Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 Yea Waynewex I know...your code seems to be working okay. I think the last code I had was working as well but there seems to be a delay on my server before it shows up in the ftp....thanks for all your help. Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962674 Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 has anyone heard of a delay in the file being uploaded? Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962682 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 Is your script slow? Or is just not showing up on your FTP client straight away? Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962685 Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 seems sometimes it will upload and other times it wont? Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962688 Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 waynewex would there be a reason why it does not upload all the time? Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962694 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 Have you got error reporting and notices on? Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962695 Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 yes I do and it throws no errors? Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962699 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 If the files are too large, then the settings in your php.ini file could be restricting them. Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962702 Share on other sites More sharing options...
play_ Posted November 21, 2009 Share Posted November 21, 2009 Check the persmission on the directory you're uploading to Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962704 Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 permission set at 755 tried to upload a little notepad doc and it does not show up.... Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962708 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 I don't get it. If error reporting and notices are turned on, you should be getting some kind of notice/error if thing aren't going right. Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962710 Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 never mind guys I went into the server and checked and the files are there just not showing up on my ftp editor for some reason....thanks for all the help. Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962712 Share on other sites More sharing options...
sandbudd Posted November 21, 2009 Author Share Posted November 21, 2009 they have changed the layout here where do I click solved? Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962714 Share on other sites More sharing options...
waynew Posted November 21, 2009 Share Posted November 21, 2009 The solved function will be offline for a while until the admins port the old mod to the new version. Link to comment https://forums.phpfreaks.com/topic/182421-writes-to-the-database-but-does-not-upload-file/#findComment-962727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.