nightkarnation Posted July 1, 2008 Share Posted July 1, 2008 Hello! I would really appreciate some help on this one: Im trying to upload a file into my phpmyadmin (locally) just in case, everything set up correctly and working on the db connection now heres my php (upload.php): <?php mysql_connect("localhost","root",""); mysql_select_db("learning"); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result = mysql_query("INSERT INTO uploads (description, data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); $id = mysql_insert_id(); print "<p>File ID: <b>$id</b><br>"; print "<p>File Name: <b>$form_data_name</b><br>"; print "<p>File Size: <b>$form_data_size</b><br>"; print "<p>File Type: <b>$form_data_type</b><p>"; print "To upload another file <a href=http://localhost> Click Here</a>"; ?> Heres my file upload form.html code: <form method="post" action="upload.php" enctype="multipart/form-data"> Description:<br> <input type="text" name="form_description" size="40"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000"> <br>File to upload:<br> <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form> And this is what i get when i browse and submit any file: Warning: fread(): supplied argument is not a valid stream resource in C:\wamp\www\Test\phpAndMysql\upload.php on line 4 Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 1, 2008 Share Posted July 1, 2008 Look at the values you're trying to enter into the database. $form_description, $data, $form_data_name, $form_data_size, $form_data_type where are these values coming from? Also, you're adding slashes to the blank value of the resource returned by fopen. You're supposed to open the file, and then go line by line through it. Your code simply doesn't do what you want it to do. php, like C and every other language, unfortunately do what you tell them to do, not what you want them to do. Quote Link to comment Share on other sites More sharing options...
nightkarnation Posted July 1, 2008 Author Share Posted July 1, 2008 Thanx for the reply Danny I took this tutorial from php.about.com This one was written by: Angela Bradley I didnt make any modifications, Clearly its wrong coded, thanx for letting me know this, Guess im gonna have to go look somewhere else than in her tutorials, Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted July 1, 2008 Share Posted July 1, 2008 post all your code on this so we can help you. Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted July 1, 2008 Share Posted July 1, 2008 Well the main question I have for you is: are you trying to upload a file into a folder? Or upload the data in a file(like a .txt or .htm file) into the database? 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.