Empfehlungen: Erweiterte Suche

Bilder Upload

Daten auslesen, verarbeiten und den Views übergeben

Bilder Upload

Beitragvon regi » So 6. Jun 2010, 20:22

Hallo Community,

ich habe einen Problem mit meinem Bilderupload in der add.tpl. Ich glaube den verursacht die Datei ads_controller.php, bin mir aber nicht sicher und hoffe, dass jemand weiß, womit mein Fehler zusammenhängt. Ich habe leider in Google und im Forum nichts dergleichen gefunden und bin noch ein Neuling was PHP betrifft :oops: ...

Hier ist mein Formular mit der add.tpl mit dem Upload Code:

Code: Alles auswählen
<tr>
    <td valign="top">Foto hinzufügen</td>
    <td>
        <input type="hidden" value="500000" name="max_file_size" />
        <input type="file" style="width: 250px;" name="file" /><br/>
        <font color="#888888">nur GIF-, JPG- und PNG-Bilder mit max. 200 KB</font>
    </td>
</tr>

{if $settings_upload == "1"}
<tr>
    <td valign="top">Weitere Anlage</td>
    <td>
        <input type="hidden" value="500000" name="max_file_size" />
        <input type="file" style="width: 250px;" name="file2" /><br/>
        <font color="#888888">nur PDF- und DOC-Dokumente mit max. 200 KB</font>
    </td>
</tr>
{/if}



und hier die ads_controller.php

Code: Alles auswählen

//MySQL inserts
                if($_FILES['file']['tmp_name'])
                {
                    switch ( $_FILES['file']['type'] )
                    {
                        case "image/gif":
                            $this->data['Ad']['img_type'] = "gif";
                        break;
                        case "image/jpeg":
                            $this->data['Ad']['img_type'] = "jpeg";
                        break;
                        case "image/png":
                            $this->data['Ad']['img_type'] = "png";
                        break;
                        case "image/jpg":
                            $this->data['Ad']['img_type'] = "jpg";
                        break;
                        default:
                            $this->data['Ad']['img_type'] = "";
                        break;
                    }//end switch
                }//end if


                if($_FILES['file2']['tmp_name'])
                {
                    switch ( $_FILES['file2']['type'] )
                    {
                        case "application/msword":
                            $this->data['Ad']['data_type'] = "doc";
                        break;
                        case "application/pdf":
                            $this->data['Ad']['data_type'] = "pdf";
                        break;
                        default:
                            $this->data['Ad']['data_type'] = "";
                        break;
                    }//end switch
                }//end if

                $this->data['Ad']['startdate'] = date("d M Y", time());
                $this->data['Ad']['content'] = strip_tags($this->data['Ad']['content']);//Kein HTML
                $users_id = $_SESSION['mYpERsOnALhaSHkeY']['User']['id'];
                $this->data['Ad']['user_id'] = $users_id;
                $this->Ad->save($this->data['Ad']);
                $last_id = $this->Ad->getLastInsertId();

                //and file upload
                $root = WWW_ROOT;

                if($_FILES['file']['tmp_name'])
                {
                    switch ( $_FILES['file']['type'] ){case "image/gif":
                            $this->gd_resize($_FILES['file']['tmp_name'], "gif", $last_id);
                            move_uploaded_file($_FILES['file']['tmp_name'], $root."upload/".$last_id."_full.gif");
                        //  copy($root."upload/".$last_id."_full.gif",  $root."upload/".$last_id.".gif");
                            chmod ($root."upload/".$last_id."_full.gif", 0755);
                            chmod ($root."upload/".$last_id.".gif", 0755);
                        break;
                        case "image/jpeg":
                            $this->gd_resize($_FILES['file']['tmp_name'], "jpeg", $last_id);
                            move_uploaded_file($_FILES['file']['tmp_name'], $root."upload/".$last_id."_full.jpeg");
                            chmod ($root."upload/".$last_id.".jpeg", 0755);
                            chmod ($root."upload/".$last_id."_full.jpeg", 0755);
                        break;
                        case "image/png":
                            move_uploaded_file($_FILES['file']['tmp_name'], $root."upload/".$last_id."_full.png");
                            copy($root."upload/".$last_id."_full.png",  $root."upload/".$last_id.".png");
                            chmod ($root."upload/".$last_id."_full.png", 0755);
                            chmod ($root."upload/".$last_id.".png", 0755);
                        break;
                        default:
                            $this->set("error","2"); //File not allowed
                        break;
                    }
                }

                if(isset($_FILES['file2']['tmp_name']))
                {
                    switch ( $_FILES['file2']['type'] )
                    {
                        case "application/msword":
                            move_uploaded_file($_FILES['file2']['tmp_name'], $root."upload/".$last_id.".doc");
                            chmod ($root."upload/".$last_id.".doc", 0755);
                        break;
                        case "application/pdf":
                            move_uploaded_file($_FILES['file2']['tmp_name'], $root."upload/".$last_id.".pdf");
                            chmod ($root."upload/".$last_id.".pdf", 0755);
                        break;
                        default:
                            $this->set("error","2"); //File not allowed
                        break;
                    }
                }
 



Aber wie gesagt, weiß ich nicht ob es an dieser liegt...Ich habe aber in keiner anderen Datei einen möglichen Hinweis gefunden. Ich hoffe sehr dass mir hier jemand helfen kann :roll:

Liebe Grüße
regi
regi
 
Beiträge: 1
Registriert: So 6. Jun 2010, 20:07

Re: Bilder Upload

Beitragvon Jörg » Di 8. Jun 2010, 21:57

Hi regi,

wo ist denn dein <form>-Tag?
Hast du den enctype auf "multipart/form-data" gestellt?

Hier ein Tipp:
http://cakebaker.42dh.com/2006/04/15/fi ... h-cakephp/
Jörg
 
Beiträge: 105
Registriert: Di 13. Mai 2008, 13:45
Wohnort: Bremen
CakePHP-Version: 2.0.3, 1.3.x
OS: Win7/Ubuntu


Zurück zu Controller

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 0 Gäste

cron