gabrielroos Posted November 18, 2013 Share Posted November 18, 2013 Ok, before I start, phpfreaks is my last resort to get help. it seems the people on the other sites are having trouble understanding and/or helping me with this... anyway, here is what I am trying to do: I have a website with a folder structure that I allow users to browse to select a category where they can upload they’re relevant pdf documents, for instance, the root folder is “data”, then they have to select a grade, like grade 12 or 11 or 10 whatever, then a subject say “geography”, “maths” or whatever, inside the selected subject they have to pick a sub category say: if they selected “geography” then ”erosion” is a subtopic for geography. This works well with the folder structure on the website, but I want to change the system to use a sql database with the relevant tables instead of folders. I have already created the sql database and written a php script to connect to the database, now I need to get the rest done…. Can anyone help me write this code, I will put dedicated pages on my website advertising your help!!! I am truly desperate here is the php code that a guy at daniweb helped me with, but I am getting a couple of problems with the upload.php file...also attached is my database for anyone willing to help me? RegardsGabriel Roos config.txt Upload.txt view.txt edynam0_mysql.txt Index.php Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 18, 2013 Share Posted November 18, 2013 I am getting a couple of problems with the upload.php file... care to share what those problems are? we are not standing right next to you, nor do we have the ability to run your code because we don't have your database tables, nor do we even know what size file you tried. Quote Link to comment Share on other sites More sharing options...
JIXO Posted November 18, 2013 Share Posted November 18, 2013 Eh, I'm sorry gabrielroos but its hard to debug this project, I'm quoting from Upload.php strting line 22 $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content = addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } .... Its not good to loop through all the file content and just addslashes, you might corrupt the file. As also for view.php, starting line 15 : while ($row = $res->fetch()){ header("Content-length: ".$row['size']); header("Content-type: ".$row['type']); if($allowDownload){ header("Content-Disposition: attachment; filename=".$row['filename']); } echo $row['filecontent']; } You cannot just echo the file !!! take a look at these tutorials the might help. PHP Tutorial - File Upload, PHP Tutorial: Uploading Files. I will try to debug the code, but please consider these tutorials. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 18, 2013 Share Posted November 18, 2013 @JIXO, if you are saving/serving the file in/from a database, you most certainly would need to escape the binary file data before putting it into a query statement and you would most certainly need to echo the contents of the file to output it to the browser after sending the appropriate headers. Quote Link to comment Share on other sites More sharing options...
JIXO Posted November 18, 2013 Share Posted November 18, 2013 @JIXO, if you are saving/serving the file in/from a database, you most certainly would need to escape the binary file data before putting it into a query statement and you would most certainly need to echo the contents of the file to output it to the browser after sending the appropriate headers. Yup my mistake. Quote Link to comment Share on other sites More sharing options...
gabrielroos Posted November 19, 2013 Author Share Posted November 19, 2013 Ok, that confirms that I suck at writing php code.... will any of you guys be willing to help me write proper code to get this system working? I even have a bribe if anyone is interested.. lol... I live in South Africa and my family owns a large game farm, if any of you are into hunting and you plan an visiting South Africa at some point, I will throw in a 2 week hunting "safari" for anyone who are willing to help...? (I might be reaching a little, but I am truly desperate) Gabriel Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 19, 2013 Share Posted November 19, 2013 i see that 4-5 interested people have downloaded your files, but no replies yet. the reason for this is programming and troubleshooting programming is an exact science and since you haven't provided any information about - I am getting a couple of problems with the upload.php file... no one here can really help you with those problems. Quote Link to comment Share on other sites More sharing options...
gabrielroos Posted November 20, 2013 Author Share Posted November 20, 2013 Ok, a guy from dannyweb helped me with code to make the above mentioned system work, he send me the .php files and told my how to change the database to get it working, I then uploaded the php files to my server and followed his instructions (which I will post a link to) to test the code, but when I browse to the upload.php file I get a error code (Fatal error: Call to a member function fetch_array() on a non-object in /home/edynam0/public_html/Upload.php on line 9) which I have no clue as to how to get around it... as for the above mentioned errors that were spotted by JIXO and yourself (mac_gyver), its Greek to me.... . I am not setting the use of the code that I got from the guy at dannyweb in stone... I will be thankful for any code that works like described in my original post... I hope I am making sense... Regards Gabriel Roos 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.