PHP Indonesia - Facebook | PHP Indonesia is a community for everyone that loves PHP. Our focus is in the PHP world but our topics encompass the entire LAMP stack. Topics include PHP coding, to memcached handling, db optimizations, server stack, web server tuning, code deploying, hosting options and much much more. Youtube Channel : http://www.youtube.com/user/OurPHPIndonesia Twitter : @php_indonesia NOTE: Rules for Wall posting: https://www.facebook.com/groups/35688476100/doc/10151597056316101/ Daftar Keanggotaan : http://www.facebook.com/groups/35688476100/doc/10150671770741101/ | |
 | Learn to Code Websites
in 10 weeks with a part time course. Learn html, css and javascript from the best instructors. Apply now!  | From our sponsors | | |
[ASK| How to upload a photo with php ?] master mau... Nov 16th 2013, 15:00, by Fitrie Utrie | [ASK| How to upload a photo with php ?] master mau nanya, proses upload foto yang mudah gimna dan scriptnya mudah dipahami ? udah beberpa kali saya buat, tapi belum berhasil
trims :) |
| | view.php
<form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="myFile"> <br> <input type="submit" value="Upload"> </form> |
| | process.php
define("UPLOAD_DIR", "/folder direktori dimana file ingin disimpan"); if (!empty($_FILES["myFile"])) { $myFile = $_FILES["myFile"]; if ($myFile["error"] !== UPLOAD_ERR_OK) { echo "<p>An error occurred.</p>"; exit; } // ensure a safe filename $name = preg_replace("/[^A-Z0-9._-]/i", "_", $myFile["name"]); // don't overwrite an existing file $i = 0; $parts = pathinfo($name); while (file_exists(UPLOAD_DIR . $name)) { $i++; $name = $parts["filename"] . "-" . $i . "." . $parts["extension"]; } // preserve file from temporary directory $success = move_uploaded_file($myFile["tmp_name"], UPLOAD_DIR . $name); if (!$success) { echo "<p>Unable to save file.</p>"; exit; } // set proper permissions on the new file chmod(UPLOAD_DIR . $name, 0644); } | | |
|
Tidak ada komentar:
Posting Komentar