Jump to content

html php and sql connection an upload


gabrielroos

Recommended Posts

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?

 

 

Regards
Gabriel Roos

config.txt

Upload.txt

view.txt

edynam0_mysql.txt

Index.php

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.... :confused: . 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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.