Page 1 of 1

file upload problem

Posted: Tue May 29, 2012 9:37 pm
by kc11
Hi everyone,

I'm trying to setup a basic file uploader for my page using http://malsup.com/jquery/form/ , jquery and codeigniter 2.1.

Following the directions on http://malsup.com/jquery/form/#getting-started, I have this form:

Code: Select all


<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       
         <base href="<?=base_url();?>">
       
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.js"></script>
    <script src="assets/jquery.form.js"></script>
 
    <script>
        // wait for the DOM to be loaded
        $(document).ready(function() {
            // bind 'myForm' and provide a simple callback function
            $('#myForm').ajaxForm(function() {
                alert("Thank you for your comment!");
            });
           
        });
    </script>
    </head>
    <body>
        <div>TODO write content</div>
       
        <?php chmod("assets/comment.php", '777')  ?>
       
        <form id="myForm" action="assets/comment.php" method="post">
    Name: <input type="text" name="name" />
    Comment: <textarea name="comment"></textarea>
    <input type="submit" value="Submit Comment" />
</form>
    </body>
</html>

I have created a file called comment.php , and put in the assets folder. The directory structure is:

[text]
application
assets
-- css
-- images
-- img
-- js
system
index.php
[/text]

When I load a and fill the form it appears to work and firebug shows:
when I look in comment.php there is nothing in it. why is the comment not posted to it? I have changed permissions in the form to '777'

Thank you,

KC

Re: file upload problem

Posted: Wed May 30, 2012 2:19 am
by requinix
Oh dear.

File uploads in PHP work by pointing a form's action to a script (also with method=post and a special enctype) which then uses the information provided by PHP itself (like file name and size) to do whatever it wants with the file (like move it somewhere or store it in a database). PHP doesn't do that part for you automatically.

That said, what you're doing isn't even file uploading. There are no file upload fields in that form.

Before a lot of other things, you have to learn how to accept form submissions using $_POST. Once you understand how that works and can use normal forms well, then you can learn the details about file uploads and $_FILES.

Re: file upload problem

Posted: Thu May 31, 2012 3:42 pm
by social_experiment
@kc11 http://malsup.com/jquery/form/#file-upload file uploads are covered on a different tab but you still need to know how use PHP's file upload functions as previously mentioned.