upload foto ke folder & database

deny · Jul 23, 2012
mas Ellyx, saya sudah coba pake script yang punya mas untuk upload foto ke folder. tetapi, masih belum bisa2 juga mas. mohon bantuannya donk mas. folder fotonya, images mas. ini script asli saya.
<?php
if (isset($_POST['daftar']))
{
	include "./config/conn.php";
	$nama=ucwords($_POST['nama']);
	$kota_asal=$_POST['kota_asal'];
	$foto=$_POST['foto'];
	$user=$_POST['user'];
	$email=$_POST['email'];
	$password=md5($_POST['password']);
	

	if (!empty($nama) && !empty($kota_asal) && !empty($foto) && !empty($user) && !empty($email) && !empty($password))
	{	
		
		$cek=mysql_db_query($db,"select * from daftar where user='$user'",$koneksi);
		$valid=mysql_num_rows($cek);
		
		if ($valid){
			echo "<script> document.location.href='signup.php?status=<font color=red>Maaf, USERNAME Anda sudah ada yang punya!!</font>'; </script>";
		}else{
			
			$insert=mysql_db_query($db,"insert into daftar(nama,kota_asal,foto,user,email,pass,tanggal) values('$nama','$kota_asal','$foto','$user','$email','$password','$tanggal')",$koneksi);
			if ($insert)
			{
				echo "<script> document.location.href='signup.php?status=Selamat bergabung dengan situs kami.'; </script>";
			}
		}
		
	}
	else
	{
		echo "<script> document.location.href='signup.php?status=<font color=red>Maaf, Data yang anda kirim belum lengkap!!</font>'; </script>";
	}
	
}

?>

<html>
<head>
<title>SignUp</title>
<script language="javascript">
<!--
function tutup()
{
	top.window.close()
}
//-->
</script>
</head>
<body>

<center>
<table width="100%" cellspacing="2" cellpadding="2" >
<tr>
<td bgcolor='#0033FF' colspan="2"><div align="center">
	<font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>[DAFTAR SLANKER/SLANKY]</strong></font></div>
</td>	
<tr>
	<td>&nbsp;</td>
</tr>
<tr>
	<td valign="top">&nbsp;</td>
	<td>
		<form name="daftar" action="signup.php" method="post">
		<table width="100%" cellspacing="2" cellpadding="2" >
			<tr>
				<td><font face="verdana" size="2">Nama Lengkap</font></td>
				<td><input type="text"  dir="ltr" size="25" name="nama"><td>
			</tr>
			
			<tr>
			  <td>Kota asal</td>
			  <td><label for="textfield"></label>
			    <input type="text" name="kota_asal" id="textfield"></td>
		    </tr>
			<tr>
			  <td>Foto</td>
			  <td><input type="file" name="foto" size="20"></td>
		    </tr>
			<tr>
				<td><font face="verdana" size="2">User name</font></td>
				<td><input type="text" size="10" name="user"></td>
			</tr>
			
			<tr>
				<td><font face="verdana" size="2">Email</font></td>
				<td>
				<input type="text" size="25" name="email"></td>
			</tr>
			
			<tr>
				<td height="30"><font face="verdana" size="2">Password</font></td>
				<td><input type="password" size="10" name="password">
				<font size="-1" color="#A0A0A4" face="verdana"> (Max 6 digit 0-9 a-z case sensitif)</font></td>
			</tr>
			
			<tr>
				<td></td><td><p>
				  <input type="submit" value="Kirim" name="daftar">
			      &nbsp;
			      <input type="button" onClick="tutup()" value="Keluar">
				  </p>
				  </td>
			</tr>
		</table>
		</form><br>
		<p align="center"><font color="#0033FF" face='verdana' size='2'><blink><? echo $_GET['status'] ?></blink></font><br></p>
	</td>
</tr>
</tr>
</table>

</center>
</body>
</html>
Silahkan login untuk menjawab!
1
Loading...
Ellyx Christian · Jul 23, 2012 · 1 Suka · 0 Tidak Suka
form kamu salah, untuk upload file form harus ditambahkan attribute enctype dengan nilai multipart/form-data seperti:
<form name="daftar" action="signup.php" method="post" enctype="multipart/form-data">

kemudian untuk upload foto, tidak menggunakan $_POST seperti yang kamu lakukan $_POST tapi menggunakan nilai yang ada di $_FILES seperti:
<?php 
$namafile = $_FILES['foto']['name'];
$size = $_FILES['foto']['size'];
$error = $_FILES['foto']['error'];
if($size > 0 && $error == 0){ //jika ukuran file lebih dari nol dan tidak terjadi error
	move_uploaded_file($_FILES['foto']['tmp_name'], 'path/to/upload/'.$namafile); //upload file
}
pelajari lagi di http://www.myphptutorials.com/tutorials/20/upload-gambar-dengan-php atau http://www.myphptutorials.com/tutorials/39/membuat-galeri-foto
<?php
if (isset($_POST['daftar']))
{
	include "./config/conn.php";
	$nama=ucwords($_POST['nama']);
	$kota_asal=$_POST['kota_asal'];
	$user=$_POST['user'];
	$email=$_POST['email'];
	$password=md5($_POST['password']);
	//upload gambar
	$foto = '';
	if($_FILES['foto']['size'] > 0 && $_FILES['foto']['error'] == 0){
		move_uploaded_file($_FILES['foto']['tmp_name'], 'foto/'.$_FILES['foto']['name']);
		$foto=$_FILES['foto']['name'];
	}
 
	if (!empty($nama) && !empty($kota_asal) && !empty($foto) && !empty($user) && !empty($email) && !empty($password))
	{	
 
		$cek=mysql_db_query($db,"select * from daftar where user='$user'",$koneksi);
		$valid=mysql_num_rows($cek);
 
		if ($valid){
			echo "<script> document.location.href='signup.php?status=<font color=red>Maaf, USERNAME Anda sudah ada yang punya!!</font>'; </script>";
		}else{
 
			$insert=mysql_db_query($db,"insert into daftar(nama,kota_asal,foto,user,email,pass,tanggal) values('$nama','$kota_asal','$foto','$user','$email','$password','$tanggal')",$koneksi);
			if ($insert)
			{
				echo "<script> document.location.href='signup.php?status=Selamat bergabung dengan situs kami.'; </script>";
			}
		}
 
	}
	else
	{
		echo "<script> document.location.href='signup.php?status=<font color=red>Maaf, Data yang anda kirim belum lengkap!!</font>'; </script>";
	}
 
}
 
?>
1
Loading...
deny · Jul 24, 2012 · 1 Suka · 0 Tidak Suka
mas Ellyx, scriptnya ud bisa di upload ke folder mas. tapi saya belum bisa nampilin fotonya nih. ud di coba kutak katik, tapi belum bisa bisa mas. ini script yang ud saya perbaiki.
    <?php
      if (isset($_POST['daftar']))
      {
      include "./config/conn.php";
      $nama=ucwords($_POST['nama']);
      $kota_asal=$_POST['kota_asal'];
      $user=$_POST['user'];
      $email=$_POST['email'];
      $password=md5($_POST['password']);
      //upload gambar
	  $foto = $_FILES['foto']['name'];
	  $size = $_FILES['foto']['size'];
	  $error = $_FILES['foto']['error'];
	  if($_FILES['foto']['size'] > 0 && $_FILES['foto']['error'] == 0){
      move_uploaded_file($_FILES['foto']['tmp_name'], 'images/'.$_FILES['foto']['name']);
      $foto=$_FILES['foto']['name'];
      }
      if (!empty($nama) && !empty($kota_asal) && !empty($foto) && !empty($user) && !empty($email) && !empty($password))
      {
      $cek=mysql_db_query($db,"select * from daftar where user='$user'",$koneksi);
      $valid=mysql_num_rows($cek);
      if ($valid){
      echo "<script> document.location.href='signup.php?status=<font color=red>Maaf, USERNAME Anda sudah ada yang punya!!</font>'; </script>";
      }else{
      $insert=mysql_db_query($db,"insert into daftar(nama,kota_asal,foto,user,email,pass,tanggal) values('$nama','$kota_asal','$foto','$user','$email','$password','$tanggal')",$koneksi);
      if ($insert)
      {
      echo "<script> document.location.href='signup.php?status=Selamat bergabung dengan situs kami.'; </script>";
      }
      }
      }
      else
      {
      echo "<script> document.location.href='signup.php?status=<font color=red>Maaf, Data yang anda kirim belum lengkap!!</font>'; </script>";
      }
       }
      ?>
<html>
<head>
<title>SignUp</title>
<script language="javascript">
<!--
function tutup()
{
	top.window.close()
}
//-->
</script>
</head>
<body>

<center>
<table width="100%" cellspacing="2" cellpadding="2" >
<tr>
<td bgcolor='#0033FF' colspan="2"><div align="center">
	<font color="#FFFFFF" face="Geneva, Arial, Helvetica, sans-serif"><strong>[DAFTAR SLANKER/SLANKY]</strong></font></div>
</td>	
<tr>
	<td>&nbsp;</td>
</tr>
<tr>
	<td valign="top">&nbsp;</td>
	<td>
		<form name="daftar" action="signup.php" method="post" enctype="multipart/form-data">
		<table width="100%" cellspacing="2" cellpadding="2" >
			<tr>
				<td><font face="verdana" size="2">Nama Lengkap</font></td>
				<td><input type="text"  dir="ltr" size="25" name="nama"><td>
			</tr>
			
			<tr>
			  <td>Kota asal</td>
			  <td><label for="textfield"></label>
			    <input type="text" name="kota_asal" id="textfield"></td>
		    </tr>
			<tr>
			  <td>Foto</td>
			  <td><input type="file" name="foto" size="20"></td>
		    </tr>
			<tr>
				<td><font face="verdana" size="2">User name</font></td>
				<td><input type="text" size="10" name="user"></td>
			</tr>
			
			<tr>
				<td><font face="verdana" size="2">Email</font></td>
				<td>
				<input type="text" size="25" name="email"></td>
			</tr>
			
			<tr>
				<td height="30"><font face="verdana" size="2">Password</font></td>
				<td><input type="password" size="10" name="password">
				<font size="-1" color="#A0A0A4" face="verdana"> (Max 6 digit 0-9 a-z case sensitif)</font></td>
			</tr>
			
			<tr>
				<td></td><td><p>
				  <input type="submit" value="Kirim" name="daftar">
			      &nbsp;
			      <input type="button" onClick="tutup()" value="Keluar">
				  </p>
				  </td>
			</tr>
		</table>
		</form><br>
		<p align="center"><font color="#0033FF" face='verdana' size='2'><blink><? echo $_GET['status'] ?></blink></font><br></p>
	</td>
</tr>
</tr>
</table>

</center>
</body>
</html>
0
Loading...
deny · Jul 24, 2012 · 0 Suka · 0 Tidak Suka
dan ini script yang buat nampilinnya mas(status.php). salah dimana y mas???
<?php
$user_name=ucwords($_SESSION['user_name']);
$time=date("G");
	?><font face="verdana" size="2" color="#FFFF66">
	<?php
	if ($time<12)
	
	{	
		$status= "  Selamat pagi ";
		}
		else if ($time<15)
		{
		$status= "  Selamat Siang ";
		}
		else if ($time<18)
		{
		$status= "  Selamat Sore ";
		}
		else
		{
		$status= "  Selamat Malam ";
	}
echo "</font>";

?>


<html>
<script language="javascript">
<!--
function konfirmasi()
{
	tanya=confirm("Apakah anda yakin akan keluar?")
	if (tanya !="0")
	{
		top.location="logout.php"
	}
}
//-->
</script>

<?php
include"./config/conn.php";
$query=mysql_db_query($db,"select * from daftar",$koneksi);
$data =mysql_fetch_array($sql);
$count=mysql_num_rows($query);
?>
<table width="15%" border="0" cellpadding="0" cellspacing="0" bgcolor="#0033FF" align="center">
<tr> 
	<td width="22%" align="right">&nbsp;</td>
	<td width="70%" bgcolor="#0033FF" ><div align="center"><strong><font face="verdana" size="2" color="#FFFFFF"><?php echo $status.$user_name; ?></font></strong></div></td>
	<td width="6%">&nbsp;</td>
</tr>
<tr>
	<td>&nbsp;</td>
	<td>
	<table width="165" align="center">
		<tr>
		<td width="157" align="center">
		<img src="images/<?php echo $data['foto'];?>" width="100" height="100" border="0"/>
	    <a href="" style="text-decoration:none " title="Keluar" onClick="konfirmasi()">
	    <b><font face="verdana" size="2" color="#FF0000">Logout</font></b></a>
		</td>
		</tr>
	</table>
	</td>
	<td>&nbsp;</td>
	<td width="2%"></td>
</tr>
<tr> 
	<td align="right">&nbsp;</td>
	<td bgcolor="#0033FF" ><div align="center"><font face="verdana" size="2" color="#FFFFFF">Jumlah Member : <?php echo $count; ?></font></div></td>
	<td>&nbsp;</td>
</tr>
</table>
0
Loading...
Ellyx Christian · Jul 29, 2012 · 0 Suka · 0 Tidak Suka