Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can try my own program. I do upload and store the data and images can be reduced in size that we can change.</p> <p>i use php and xampp. directory :</p> <pre><code>C:\xampp\htdocs\phpyan\6_Database_2 6_Database_2 : ..images (dir) ..packages (dir) ..input_personal_info.php (file) ..images ..small(dir) ..more pict (file picture) ----------------------------- ..packages ..ClassDatabase.php ..Personal.php </code></pre> <p>in the "images folder" there is a folder called "small"</p> <p>notes : <em>and in the package folder I keep the classes to function as a function of storing data and uploading image in small size</em></p> <p>input_personal_info.php</p> <pre><code>&lt;?php include 'packages/ClassDatabase.php'; include 'packages/Personal.php'; ?&gt; &lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;Input Personal Information&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Personal Information&lt;/h1&gt; &lt;form enctype="multipart/form-data" action="" name="frm_personal_info" method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;First Name&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="First_Name"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Last Name&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="Last_Name"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Date Birth&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="Date_Birth"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Gender&lt;/td&gt; &lt;td&gt; &lt;select name="Gender"&gt; &lt;option value=""&gt;Gender...&lt;/option&gt; &lt;option value="Pria"&gt;Pria&lt;/option&gt; &lt;option value="Wanita"&gt;Wanita&lt;/option&gt; &lt;option value="Lainnya"&gt;Lain..&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Photo Profile&lt;/td&gt; &lt;td&gt;&lt;input type="file" name="Photo_Profile"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;About&lt;/td&gt; &lt;td&gt;&lt;textarea name="About" rows="4" cols="30"&gt;&lt;/textarea&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="2"&gt;&lt;input type="submit" name="submit" value="Save"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php // connect with database $connector = new ClassDatabase("localhost","root","","RawnayDB"); $connector-&gt;connect(); if (isset($_POST['submit'])) { // assign values on variabel $first_name = $_POST['First_Name']; $last_name = $_POST['Last_Name']; $date_birth = $_POST['Date_Birth']; $gender = $_POST['Gender']; $about = $_POST['About']; $dir = "images/"; $dir2 = "images/small/"; $photo_name = $_FILES['Photo_Profile']['name']; $photo_error = $_FILES['Photo_Profile']['error']; $photo_type = $_FILES['Photo_Profile']['type']; $photo_size = $_FILES['Photo_Profile']['size']; $photo_tmp = $_FILES['Photo_Profile']['tmp_name']; $personals = new Personal(); // save file foto $personals-&gt;uploadPic($dir,$photo_name,$photo_tmp); // save pic small $personals-&gt;thumbPic($dir2,$photo_name); // save data $personals-&gt;savePersData($first_name,$last_name,$date_birth,$gender,$photo_name,$about); } ?&gt; </code></pre> <p>packages/ClassDatabase.php</p> <pre><code>&lt;?php // class Database class ClassDatabase{ var $host; var $user; var $pswd; var $db; function ClassDatabase($host,$user,$pswd,$db){ $this-&gt;host = $host; $this-&gt;user = $user; $this-&gt;pswd = $pswd; $this-&gt;db = $db; } function connect(){ // Connection Test if(mysql_connect($this-&gt;host,$this-&gt;user,$this-&gt;pswd)) {mysql_select_db($this-&gt;db);} else {echo "Connection Failed";} } } ?&gt; </code></pre> <p>packages/Personal.php //> class</p> <pre><code>&lt;?php // class personal class Personal{ var $tabel = "personal"; var $photo_original; var $photo_small; var $width; var $height; var $thumbWidth = 100; var $thumbHeight; function savePersData($fstnm,$lstnm,$dtbrth,$gndr,$photo_name,$about){ $small = $this-&gt;photo_small; $original = $this-&gt;photo_original; $photo_name = "Pic".$fstnm; $query = "INSERT INTO $this-&gt;tabel VALUES('','$fstnm','$lstnm','$dtbrth','$gndr','$photo_name','$small','$original','$about');"; if(mysql_query($query)){ echo "&lt;script&gt;alert('penyimpanan sukses');&lt;/script&gt;"; } } function uploadPic($dir,$photo_name,$photo_tmp){ is_uploaded_file($photo_tmp); $check = move_uploaded_file($photo_tmp,$dir.$photo_name); if($check){ $this-&gt;photo_original=$dir.$photo_name; } } function thumbPic($dir2,$filename){ $photo_original = imagecreatefromjpeg($this-&gt;photo_original); $this-&gt;width = imagesx($photo_original); $this-&gt;height = imagesy($photo_original); $this-&gt;thumbHeight = ($this-&gt;thumbWidth/$this-&gt;width)*$this-&gt;height; // resample picture $gbr_thumb = imagecreatetruecolor($this-&gt;thumbWidth,$this-&gt;thumbHeight); imagecopyresampled($gbr_thumb,$photo_original,0,0,0,0,$this-&gt;thumbWidth,$this-&gt;thumbHeight,$this-&gt;width,$this-&gt;height); // Save your directory $acak = rand(00000,999999); imagejpeg($gbr_thumb, $dir2."Small_Rawnay_Pic_".$acak.".jpeg"); $this-&gt;photo_small = $dir2."Small_Rawnay_Pic_".$acak.".jpeg"; } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload