Kas

9

PHP Faces ile Dosya Upload

By Hüseyin Bora

File bileşeni tarayıcıda bir dosya upload kutusu oluşturur ve gönderilen dosyayı upload metodu ile sunucu üzerinde upload işlemini gerçekleştir. File etiketinin path niteliğine sunucuya trafnsfer edilen dosyanın kayıt edileceği dizin yazılmalıdır.

Örnek Dosya Upload
View Dosyası upload bileşeninin tanımlanması

<html>
<head>
<title>Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<faces>
<@import prefix="f" taglib="phpf.ui.*"/>
<f:form id="form">
<f:file id="dosya" path="resimler"/>
<f:button id="b" text="Yükle" onclick="actionevent" forname="form"/>
</f:form>
</faces>
</body>
</html>

Örnek Upload  Kontrolcüsü

<?php

import("phpf.controllers.facete");
class DosyaYukle extends Facete {

public function DosyaYukle() {

parent::Facete();
$this->render("yukle.html");
}
function buttonClicked($evt){
$this->resimler->upload();
}
}
?>

FileValidator ve File Bileşeni ile Upload

FileValidator file bişeleni ile birlikte kullanılır örneğin belli boyuttun üzerindeki dosyaların yüklenmemesini ya da belli dosya formatlarının yüklenmesi gerekebilir. FileValidator sınıfının 3 metodu bulunur length (kabul edilen en fazla dosya boyutu)tyeps (Kabul edilen dosya formatları) exists(aynı dosya adında başkabir dosanın blunması durumu)

Örnek Boyutu 50000 den küçük olan GIF ve JPG formatlarını sunucu ya yüklemek

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<faces>
<@import prefix="f" taglib="phpf.ui.*"/>
<f:form id="form">
<f:file id="file" path="resimler/"    length="50000"
validator="filevalidator"
rule="types,length" types="image/jpeg,image/gif"
message="Desteklenmeyen Dosya Formatı,50000 byte tan büyük dosya"
messagefor="hata,hata"/>
<f:message id="hata"/>
<f:button id="b" text="Yükle" onclick="actionevent" forname="form"/>
</f:form>
</faces>
</body>
</html>

PHP tarafı

<?php

import("phpf.controllers.facete");

import("io.filevalidator");
class DosyaYukle extends Facete {

public function DosyaYukle() {

parent::Facete();
$this->render("yukle.html");
}
function buttonClicked($evt){
$this->resimler->upload();
$this->hata->setText("Dosya Yüklendi..");
}
}
?>

<?php 
import("phpf.controllers.facete");
class DosyaYukle extends Facete {
    public function DosyaYukle() {
        parent::Facete();
        $this->render("yukle.html");
    }
    
     function buttonClicked($evt){
         $this->resimler->upload();
     } 
}
?>

Bu başlık için sizde yorum yazabilirsiniz.