# Any Cakephp 3 Image Uploading tutorial Online?

**URL:** <https://discourse.cakephp.org/t/any-cakephp-3-image-uploading-tutorial-online/1647>\
**Category:** Need Help\
**Tags:** behavior\
**Created:** [December 1, 2016, 7:48am UTC](https://discourse.cakephp.org/t/any-cakephp-3-image-uploading-tutorial-online/1647 "2016-12-01T07:48:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![clementcrownrise](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clementcrownrise](https://discourse.cakephp.org/u/clementcrownrise)\
**Post date:** [December 1, 2016, 7:48am UTC](https://discourse.cakephp.org/t/any-cakephp-3-image-uploading-tutorial-online/1647/1 "2016-12-01T07:48:00Z")

</div>

Hi guys, does anyone have know of a cakephp 3 upload image upload tutorial online?

I have been having problem uploading a file from my cakephp form.

Your help would be appreciated.

---

<div class="post-metadata">

**Author:** ![jimgwhit](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jimgwhit/32/378_2.png) [@jimgwhit](https://discourse.cakephp.org/u/jimgwhit)\
**Post date:** [December 2, 2016, 2:34am UTC](https://discourse.cakephp.org/t/any-cakephp-3-image-uploading-tutorial-online/1647/2 "2016-12-02T02:34:55Z")

</div>

I use this:

```auto
    public function add()
    {
        $dogs = TableRegistry::get('Dogs');
        $lid = $dogs->find()->where(['dogid >' => 0])->count();
        echo $lid;
        //$this->autoRender = false;
        if (isset($_POST['submit'])) {

            // exit();
            $lid = $lid + 1;
            $target_path = WWW_ROOT . 'img/imgdogs/';
            $file_name = $_FILES['ufile']['name'];
            $parts = explode(".", $file_name);
            $fname = $parts[0];
            $new_file_name = $fname . $lid . "." . "jpg";
            //$path = $new_file_name;
            $to_path = $target_path . $fname . $lid . "." . "jpg"; //set the target path with a new name of image
            //echo $path;

            if ($file_name != '') {

                if (move_uploaded_file($_FILES['ufile']['tmp_name'], $to_path)) {
                    echo "Successful<BR/>";

                    echo "File Name :" . $new_file_name . "<BR/>";
                    echo "File Size :" . $_FILES['ufile']['size'] . "<BR/>";
                    echo "File Type :" . $_FILES['ufile']['type'] . "<BR/>";
                } else {
                    echo "Error";
                }
            }

            $dogpic = Cln::fixValue($new_file_name);
            $dogname = ucfirst(Cln::fixValue($_POST['dogname']));
            $sex = ucfirst($_POST['sex']);
            $comments = Cln::fixValue($_POST['comments']);
            $adopted = (isset($_POST['adopted']) == '1' ? '1' : '0'); ///added
            $lastedit = date("Y-m-d H:i:s");
            echo "adpt=" . $adopted . "aaa";

            if (!isset($error)) {
                $postdata = array(
                    'dogpic' => $dogpic,
                    'dogname' => $dogname,
                    'sex' => $sex,
                    'comments' => $comments,
                    'adopted' => $adopted,
                    'lastedit' => $lastedit
                );

                //$dogs = TableRegistry::get('Dogss');
                $query = $dogs->query();
                $query->insert(['dogpic', 'dogname', 'sex', 'comments', 'adopted', 'lastedit'])
                        ->values($postdata)
                        ->execute();
            }
        }

        $this->viewBuilder()->layout('dogedittpl');
        //$this->set(compact('data2'));
    }

```

and view

```auto
<div style="margin-right:auto;margin-left:0px; width:900px;">

    <form action='' method='post' enctype="multipart/form-data">
        <table style="border:none; width: 700px;">
            <tr>
                <td>dogpic:</td>
                <td>
                <!--<input type="text" name="dogpic" id="dogpic">-->
                    <input name="ufile" type="file" id="ufile" size="50" /></td>
                </td>
            </tr>

            <tr>
                <td>dogname:</td>
                <td>
                    <input type="text" name="dogname" id="dogname">
                </td>
            </tr>

            <tr>
                <td>sex:</td>
                <td>
                    <input type="text" name="sex" id="sex">
                </td>
            </tr>

            <tr>
                <td>comments:</td>
                <td style="width: 200px;">
                    <input type="text" name="comments" id="comments" size="200">
                </td>
            </tr>

            <tr>
                <td>adopted:</td>
                <td><input type="checkbox" name="adopted" id="adopted" value="1" /></td>
            </tr>

        </table>
        <!--<input type="hidden" name="token" value="<?php //echo $token; ?>" />-->
        <p><input type='submit' name='submit' value='Add'></p>
    </form>

</div>

```

of course view is part of a layout

This works, just not cleaned up yet. Don’t worry about cake, just concetrate on php uploading.

---

<div class="post-metadata">

**Author:** ![TheMiller](https://avatars.discourse-cdn.com/v4/letter/t/3ec8ea/32.png) [@TheMiller](https://discourse.cakephp.org/u/TheMiller)\
**Post date:** [December 2, 2016, 6:51am UTC](https://discourse.cakephp.org/t/any-cakephp-3-image-uploading-tutorial-online/1647/3 "2016-12-02T06:51:49Z")

</div>

Hello.

I use this one: [http://josediazgonzalez.com/2015/12/05/uploading-files-and-images/](http://josediazgonzalez.com/2015/12/05/uploading-files-and-images/)

Very clean, well structured and easy to handle.

---

<div class="post-metadata">

**Author:** ![clementcrownrise](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clementcrownrise](https://discourse.cakephp.org/u/clementcrownrise)\
**Post date:** [December 2, 2016, 7:40am UTC](https://discourse.cakephp.org/t/any-cakephp-3-image-uploading-tutorial-online/1647/4 "2016-12-02T07:40:06Z")

</div>

Thanks for your response @ jimgwhit,

---

<div class="post-metadata">

**Author:** ![clementcrownrise](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clementcrownrise](https://discourse.cakephp.org/u/clementcrownrise)\
**Post date:** [December 2, 2016, 7:40am UTC](https://discourse.cakephp.org/t/any-cakephp-3-image-uploading-tutorial-online/1647/5 "2016-12-02T07:40:27Z")

</div>

thanks Themiller, I really appreciate

---

<div class="post-metadata">

**Author:** ![clementcrownrise](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clementcrownrise](https://discourse.cakephp.org/u/clementcrownrise)\
**Post date:** [December 2, 2016, 10:00am UTC](https://discourse.cakephp.org/t/any-cakephp-3-image-uploading-tutorial-online/1647/6 "2016-12-02T10:00:08Z")

</div>

I tried to use this plugin, but It kept giving me errors, that plugin could not be loaded.

Please can you help me further?
