4 Replies - 1203 Views - Last Post: 13 October 2009 - 08:53 AM Rate Topic: -----

#1 sinans11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-October 09

file upload

Post icon  Posted 13 October 2009 - 03:19 AM

hi can someone please help with a problem iv been having. basically the $_FILES['userfile'] doesnt actually get the data and store it. I thought maybe its because of the $_GET method which it still maybe but I worked on this for ver long. I tried echo'ing the data in the $fileType, $fileSize, etc and its empty so theres a problem with the data being parsed. below is the code

if(isset($_GET['kaydet'])){
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;
//<input name="userfile" type="file" id="userfile">

if(mysql_query("INSERT INTO video(name,type,size,path) VALUES ('$tmpName','$fileType','$fileSize','$filePath') "))
{
echo 'Kaydınız gerçekleştirildi.<meta http-equiv="refresh" content="2;URL=index.php">';
}else{
echo "kayit yapilamadi.";
}
}

if(isset($_GET['kat']))
{
$tarih = date('d.m.y');
print "<table width=\"100%\" cellpadding=\"0\" class=\"tfont\" cellspacing=\"0\" border=\"0\">
<form method=\"POST\" action=\"video.php?kaydet\">
<table border=\"0\" width=\"100%\">
	<tr>
	<td width=\"49%\" class=\"tfont\">►Kategori :</td>
	<td width=\"49%\">";?>
<?php
echo "<select style='border-style: solid; border-width: 1; background-color: #4d79bc' class='tfont' size='1' name='1'>";
$kategoriler = mysql_query("SELECT id,kad FROM kategori");
while ($kategori = mysql_fetch_array($kategoriler))
{
echo "<option value='".$kategori['id']."'>".$kategori['kad']."</option>";
}
echo "</select>";
?>
	<td width=\"49%\" class=\"tfont\">►Video URL :</td>
	<td width=\"49%\"><input name=\"userfile\" type=\"file\" id=\"userfile\" style='border-style: solid; border-width: 1; background-color: #4d79bc' class='tfont'>



Is This A Good Question/Topic? 0
  • +

Replies To: file upload

#2 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: file upload

Posted 13 October 2009 - 03:44 AM

Check these some tutorials in Dream.In.Code by Dream.In.Code Experts

Tutorials:
PHP - Uploading a File by e_barroga
Upload A File From A Form by skyhawk133
Uploading Images with PHP by akozlik
File Uploads Tutorial by Pilot-Doofy
Securing File Uploads by Pilot-Doofy


Source Codes:
Smart file upload by Auzzie
File upload with PHP by PsychoCoder
Upload files by William_Wilson
Was This Post Helpful? 0
  • +
  • -

#3 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: file upload

Posted 13 October 2009 - 04:02 AM

your problem is in your HTML form, when you want to use file with form then form's enctype must be application/x-www-form-urlencoded
<form action="" method="post" enctype="application/x-www-form-urlencoded" name="form1">

:)
Was This Post Helpful? 0
  • +
  • -

#4 sinans11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-October 09

Re: file upload

Posted 13 October 2009 - 04:55 AM

well guys I'm affraid it still aint working there is nothing wrong with the upload script as I used this code on another form with direct html rather then being echod and it works fine. also another thing that I shoulf have mensioned is that other data is passed from the forms

example: Code snippet (not the hole code)
$a = $_POST['1'];
$b = $_POST['2'];
$c = $_POST['userfile'];
$d = $_POST['4'];
$e = $_POST['5'];
$f = $_POST['6'];
$g = $_POST['7'];
$h = 0;

if(mysql_query("INSERT INTO video(kid,ad,url,rurl,aciklama,tarih,tur,hit,name,type,size,path) VALUES ('$a','$b','$c','$d','$e','$f','$g','$h') "))
{
echo 'Kaydınız gerçekleştirildi.<meta http-equiv="refresh" content="2;URL=index.php">';
}else{
echo "kayit yapilamadi.";
}
}
//<form action="" method="post" enctype="application/x-www-form-urlencoded" name="form1">
if(isset($_GET['kat']))
{
$tarih = date('d.m.y');
print "<table width=\"100%\" cellpadding=\"0\" class=\"tfont\" cellspacing=\"0\" border=\"0\">
<form method=\"POST\" action=\"video.php?kaydet\" enctype=\"application/x-www-form-urlencoded\">
<table border=\"0\" width=\"100%\">
	<tr>
	<td width=\"49%\" class=\"tfont\">►Kategori :</td>
	<td width=\"49%\">";?>
<?php
echo "<select style='border-style: solid; border-width: 1; background-color: #4d79bc' class='tfont' size='1' name='1'>";
$kategoriler = mysql_query("SELECT id,kad FROM kategori");
while ($kategori = mysql_fetch_array($kategoriler))
{
echo "<option value='".$kategori['id']."'>".$kategori['kad']."</option>";
}
echo "</select>";
?>
	<?php echo "</td>
  </tr>
	<tr>
	<td width=\"49%\" class=\"tfont\">►Video Adı :</td>
	<td width=\"49%\"><input type=\"text\" style='border-style: solid; border-width: 1; background-color: #4d79bc' class='tfont' name=\"2\" value=\"\"size=\"27\"></td>
  </tr>
	  <tr>



you see this code works fine. the file is added to the sql database

what messes up is if i add
$uploadDir = '/home/sites/sinan.com/public_html/upload/upload_file/';


$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}

include 'config.php';

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}


<td width=\"49%\" class=\"tfont\">►Video URL :</td>
<td width=\"49%\"><input name=\"userfile\" type=\"file\" id=\"userfile\" style='border-style: solid; border-width: 1; background-color: #4d79bc' class='tfont'>



You see the data gotten from userfile is not passed to example: $fileName = $_FILES['userfile']['name']; or any of the others. I hope I never confused anyone.

This post has been edited by sinans11: 13 October 2009 - 04:59 AM

Was This Post Helpful? 0
  • +
  • -

#5 sinans11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-October 09

Re: file upload

Posted 13 October 2009 - 08:53 AM

noorahmad thanks for you help what you said was write but also

I had forgotten to declare the name on the submit button. once i sorted that out I was able to call the POST method which sorted the problem out.

Thanks anyway man appreciated
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1