Tolong pilih kategori sesuai, jenis posting (pertanyaan atau bukan) dan sertakan tag/topik yang sesuai misal komputer, php, mysql, dll.
Promosi atau posting tidak pada tempatnya akan kami hapus.
Mencantumkan kode program di posting Anda, tolong ikuti aturan yang sesuai, baca http://diskusiweb.com/discussion/39204/aturan-cara-menyisipkan-kode-program-di-diskusiweb

Baca cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

multiple image upload

Gue dunlud class untuk upload gambar, nah gue OOP masih meraba2 :( kalo secara prosedure bisa.

1) gimana caranya biar script ni bisa gue manfaatin untuk upload gambar lebih dari satu :

2) <input name="imgname[]" type="file" /> // untuk multiple


class upload {
 
function create_thumb(){
// getting file extension
$uploadedfile = $_FILES[$this-&gt;thisimage]['name'];
$names = explode(".",basename($uploadedfile));
$namess = $names[1]; // rhis is file extension
 
// creating thumb pic
$small_th = imagecreatefromjpeg($filename);
$thumbw =imagesx($small_th);
$thumbh = imagesy($small_th);
$mythumb = imagecreatetruecolor(75, 75);
$mythumbimg = imagecopyresampled($mythumb, $small_th, 0, 0, 0, 0, 75, 75, $thumbw, $thumbh);
$filename = "$mainfoldername/$squaresmallthumb/". $_FILES[$this-&gt;thisimage]['name'];
imagejpeg($mythumb,$filename,100);
rename("$filename", "$mainfoldername/$squaresmallthumb/$thistime.$namess");
 
}
 
}
 
//file procced single upload
 
$images -&gt;thisimage = 'imgname';
$images = new upload <span class="br0"></span>;
$images-&gt; create_thumb();
 
//HTML
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="imgname" type="file">
<input name="Submit" value="Submit" type="submit">
</form>

Tanggapan

  • edited November 2013
    $images ->thisimage = 'imgname';

    itu merujuk ke <input name="imgname" type="file">

    dipake di : $uploadedfile = $_FILES[$this->thisimage]['name'];

    pilihan elo 2 :
    - ubah class nya
    - atau ubah cara penggunaan class nya

    yg paling mudah elo pahami kemungkinan yg ubah cara penggunaan class nya

    <input name="imgname[]" type="file">

    di php nya :

    $images = new upload();

    $multifiles = $_FILES;
    foreach($multifiles['imgname'] as $singlefile) {
      $_FILES['singlefile'] = $singlefile;
      $images ->thisimage = 'singlefile';
      $images-> create_thumb();
    }

    btw, gw kok kagak ngeliat proses upload nya ?
    cuma ada proses create thumbnail doang ?

  • edited November 2013
    Kalo yg mas kasi sample di atas tuh mengubah penggunaan classnya ya? kalo ubah class pasti ribet ya.. :)

    Proses uploadnya ini mas untuk main gambarnya:

            $target_path = "$mainfoldername/$mainimgfolder/" . basename( $_FILES[$this->thisimage]['name']);    
            if(move_uploaded_file($_FILES[$this->thisimage]['tmp_name'], $target_path)) {
                $mainimages = basename($_FILES[$this->thisimage]['name']);   
            }

    $_SESSION['random_key'] = strtotime(date('Y-m-d H:i:s'));
            $thistime = $_SESSION['random_key'].'_'.md5(time());
            rename("$mainfoldername/$mainimgfolder/$mainimages", "$mainfoldername/$mainimgfolder/$thistime.$namess");
            $imagename = "$mainfoldername/$mainimgfolder/$thistime.$namess";
  • Undefined index name mas di line 39;  line 39 ini: $uploadedfile = $_FILES[$this->thisimage]['name'];
  • hoalah, ternyata kebalik ...

    model index array di $_FILES kalo multi itu :
    $_FILES['var']['name'][...]

    bukan
    $_FILES['var'][...]['name']

    ya bentuknya jadi :

    $multifiles = $_FILES;
    foreach($multifiles['imgname']['error'] as $k => $error) {
      if($error==0) {
        foreach($multifiles['imgname'] as $element => $v) {
          $_FILES['singlefile'][$element] = $multifiles['imgname'][$element][$k];
        }
        $images ->thisimage = 'singlefile';
        $images-> create_thumb();
      }
    }

    elo pahami sendiri ...
  • $_FILES['var']['name'][...]
    Kalo yg di atas seh paham mas, Kalo di OOP cara ubah penggunaan class yang ni $_FILES[$this->thisimage]['name']; kagak ada bayangan biar bisa hasil akhirnya spt  $_FILES['var']['name'][...] :)

    Oce deh tak coba dulu Mas...
Sign In or Register to comment.