I've a form like this : <form action="http://localhost.com/pwa/pwafiles/savePwafiles/" id="notebook" autocomplete="off" ...

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your PHP question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your PHP question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

Customer

I've a form like this :

 <form action="http://localhost.com/pwa/pwafiles/savePwafiles/" id="notebook" autocomplete="off"  method="post">                    <p>
                    <input name="userId" value=" ***-***-**** " type="hidden">
                    <label for="title">Title: </label>

                    <input name="title" id="title" class="text formfield" size="50" type="text">
                </p>
                <p></p>
                <p>
                    <label for="date">Date: </label>
                    <span>
                        <select id="month" class="mon" name="month" tabindex="">
                            <option value="" selected="selected">Month</option>

                                                            <option value="01">
                                        January                                </option>
                                                            <option value="02">
                                        February                                </option>
                                                            <option value="03">
                                        March                                </option>
                                                            <option value="04">

                                        April                                </option>
                                                            <option value="05">
                                        May                                </option>
                                                            <option value="06">
                                        June                                </option>
                                                            <option value="07">
                                        July                                </option>

                                                            <option value="08">
                                        August                                </option>
                                                            <option value="09">
                                        September                                </option>
                                                            <option value="10">
                                        October                                </option>
                                                            <option value="11">

                                        November                                </option>
                                                            <option value="12">
                                        December                                </option>
                                                        </select>
                    </span>
                    <span>&nbsp;</span>
                    <span>
                        <select id="day" class="dy" name="day" tabindex="1">

                            <option value="" selected="selected">Day</option>
                                                            <option value=" 1">
                                         1                                </option>
                                                            <option value=" 2">
                                         2                                </option>
                                                            <option value=" 3">
                                         3                                </option>

                                                            <option value=" 4">
                                         4                                </option>
                                                            <option value=" 5">
                                         5                                </option>
                                                            <option value=" 6">
                                         6                                </option>
                                                            <option value=" 7">

                                         7                                </option>
                                                            <option value=" 8">
                                         8                                </option>
                                                            <option value=" 9">
                                         9                                </option>
                                                            <option value="10">
                                        10                                </option>

                                                            <option value="11">
                                        11                                </option>
                                                            <option value="12">
                                        12                                </option>
                                                            <option value="13">
                                        13                                </option>
                                                            <option value="14">

                                        14                                </option>
                                                            <option value="15">
                                        15                                </option>
                                                            <option value="16">
                                        16                                </option>
                                                            <option value="17">
                                        17                                </option>

                                                            <option value="18">
                                        18                                </option>
                                                            <option value="19">
                                        19                                </option>
                                                            <option value="20">
                                        20                                </option>
                                                            <option value="21">

                                        21                                </option>
                                                            <option value="22">
                                        22                                </option>
                                                            <option value="23">
                                        23                                </option>
                                                            <option value="24">
                                        24                                </option>

                                                            <option value="25">
                                        25                                </option>
                                                            <option value="26">
                                        26                                </option>
                                                            <option value="27">
                                        27                                </option>
                                                            <option value="28">

                                        28                                </option>
                                                            <option value="29">
                                        29                                </option>
                                                            <option value="30">
                                        30                                </option>
                                                            <option value="31">
                                        31                                </option>



                        </select>
                    </span>
                    <span>&nbsp;</span>
                    <span>
                        <select id="byear" class="yr" name="year" tabindex="2">
                            <option value="" selected="selected">Year</option>
                                                            <option value="2001">2001</option>
                                                            <option value="2002">2002</option>

                                                            <option value="2003">2003</option>
                                                            <option value="2004">2004</option>
                                                            <option value="2005">2005</option>
                                                            <option value="2006">2006</option>
                                                            <option value="2007">2007</option>
                                                            <option value="2008">2008</option>

                                                            <option value="2009">2009</option>
                                                            <option value="2010">2010</option>
                                                            <option value="2011">2011</option>
                                                            <option value="2012">2012</option>
                                                            <option value="2013">2013</option>
                                                            <option value="2014">2014</option>

                                                            <option value="2015">2015</option>
                                                            <option value="2016">2016</option>
                                                            <option value="2017">2017</option>
                                                            <option value="2018">2018</option>
                                                            <option value="2019">2019</option>
                                                            <option value="2020">2020</option>

                                                        </select>
                    </span>
                </p>
                <p></p>

                <p>
                    <label for="note">File: </label>
                    <input name="pwafiles" class="formfield" id="note" type="file">
                </p>

                <p></p>

                <p align="center">
                    <label for="button"></label>
                    <input id="button" src="http://localhost.com/pwa/image/save.gif" name="Submitnote" value="addnewnote" type="image">
                </p>
                </form>

and in server side I made a code like this:

 public function savePwafiles() {
    $userId = $_post('userId');
    $title = $_post('title');
    $day = $_post('day');
    $mon = $_post('month');
    $year = $_post('year');
    $date = $year."-".$mon."-".$day;

    $filename = $_FILES['pwafiles']['name'];
    $tempfile = $_FILES['pwafiles']['tmp_name'];
    $filetype = $_FILES['pwafiles']['type'];
    $filesize = $_FILES['pwafiles']['size'];

    $fileext  = array_pop(explode('.', $filename));
    $newfile = time().".".$fileext;

    // $Pwafiles = $this->input->post('pwafiles');

    $len1 = strlen($title);
    // $len2 = strlen($Pwafiles);

    $space = ($len1+$filesize)/(1024*1024);

    $this->db->select(AccountConfig::DB_FILED_USER_USED_QUOTA);
    $this->db->select(AccountConfig::DB_FIELD_USER_ACCOUNT_QUOTA);
    $this->db->where(AccountConfig::DB_FIELD_USER_ID,$userId);

    $userspace = $this->db->get(AccountConfig::TABLE_USER);

    $update_space = $userspace->row(0)->used_quota + $space;

    if($update_space <= $userspace->row(0)->account_quota) {
        if($title!=null && $tempfile!=null && move_uploaded_file($tempfile, "files/".$newfile)) {


            $this->db->set('userid',$userId);
            $this->db->set('title',$title);
            $this->db->set('date',$date);
            $this->db->set('filesize',$filesize);
            $this->db->set('filetype',$filetype);
            $this->db->set('filename',$newfile);
            $this->db->insert(AccountConfig::TABLE_PWAFILES);

            $result = $this->db->insert_id();

            $sql = "update ".AccountConfig::TABLE_USER." set ".
                AccountConfig::DB_FILED_USER_USED_QUOTA." = ".$update_space." where ".
                AccountConfig::DB_FIELD_USER_ID." = '".$userId."'";

            $query = $this->db->query($sql);

            $result = 1;
        }
        else {
            $result = 0;
        }
    }
    else {
        $result = 10; // memory overflowed
    }
    return $result;
}

But my file is not uploading, what is the fault, please any expert help me.

Posted
Albert Shohez
Programmer

Everything is OK, you just made a mistake or forgot to add encytype="multipart/form-data" at beginning form tag.

Here it what you made :

<form action="http://localhost.com/pwa/pwafiles/savePwafiles/" id="notebook" autocomplete="off"  method="post">  

And here it is , what it should be like this:

<form action="http://localhost.com/pwa/pwafiles/savePwafiles/" id="notebook" autocomplete="off"  method="post" encytype="multipart/form-data" >
Posted
Customer

thanks a lot, you saved me from a trap.

Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More PHP Questions...

Ask Your PHP Question & Get An Answer Now!