file upload problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kc11
Forum Commoner
Posts: 73
Joined: Mon Sep 27, 2010 3:26 pm

file upload problem

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: file upload problem

Post 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.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: file upload problem

Post 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.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply