BTC USD 63,955.6 Gold USD 4,467.91
Time now: Jun 1, 12:00 AM

Upload Form - Dah selesai!

izwan_biz

Fun Poster
Messages
400
Joined
May 22, 2009
Messages
400
Reaction score
21
Points
15
Salam semua...
nak tanya la.. macam mana nak buat satu form yg bleh upload gambar terus ke email kita?
maknanya kat situ dia ada :
1- satu form
2- satu button browse(untuk search file gambar tu dalam PC)
3- butang submit

:D simple je soalan aku..


UPDATE! :


Namakan fail ni uploadform.htm . Pastikan yg merah tu tepat. Kalau file tu dalam sub folder pastikan link ke sub folder. cth: kalau fail upload.php tu letak dalam sub folder 'php', dia akan jadi gini : '../php/upload.php'.
Code:
<html>
<head>
<title></title>
</head>

<body>

<form action="[COLOR="Red"]upload.php[/COLOR]" method="post" enctype="multipart/form-data">
   <p>
      <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
      <button>Upload File</button>
   <p>
</form>

</body>
</html>


Namakan fail ni upload.php . Pastikan tempat/folder mana yang nak simpan gambo tu..(rujuk warna merah)
Code:
<?php
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png');
      $max_filesize = 524288;
      $upload_path = '[COLOR="Red"]../public_html/gambar/[/COLOR]';

 
   $filename = $_FILES['userfile']['name'];
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
 
   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');
 
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');
 
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');
 
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Gambar telah berjaya disimpan!';
      else
         echo 'There was an error during the file upload.  Please try again.';
 
?>

Terima kasih la kepada yang banyak sangat menolong tu... :((:((:((:((
 
Last edited:
dl html ada satu form element tu nama dia file..memang utk upload file..tapi meta kena tukar jadi application if aku x silap..then method post form ko tu ko direct ke satu file (ex : process.php) utk process file tu..

ada mcm2 approach..aku suggest google..rakan terbaik programmer..
 
cam ni bleh ke?

Code:
<form action="./upload.php" method="post" enctype="multipart/form-data">
   <p>
      <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br />
      <button>Upload File</button>
   <p>
</form>


Code:
<?php
   // Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
      $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
      $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory).
 
   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');
 
   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');
 
   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');
 
   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed :(.
 
?>
 
yg merah tu aku nak letak ape ye?

Code:
<?php
   // Configuration - Your Options
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation.
      $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
      $upload_path = [B][COLOR="Red"]'./files/'[/COLOR][/B]; // The place the files will be uploaded to (currently a 'files' directory).
 
   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
   $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   if(!in_array($ext,$allowed_filetypes))
      die('The file you attempted to upload is not allowed.');
 
   // Now check the filesize, if it is too large then DIE and inform the user.
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die('The file you attempted to upload is too large.');
 
   // Check if we can upload to the specified path, if not DIE and inform the user.
   if(!is_writable($upload_path))
      die('You cannot upload to the specified directory, please CHMOD it to 777.');
 
   // Upload the file to your specified path.
   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
         echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked.
      else
         echo 'There was an error during the file upload.  Please try again.'; // It failed :(.
 
?>
 
update post 1... :(( :((
letih den selongkar kat google tu.. nak meletop kepala nie..
 
u nak upload ur image n store into database kah atau direct upload image n store into a folder ?
 
gambate.........!!!You habe long way to go..just keep moving...
 
Back
Top
Log in Register