uploader

Hi I have a problem with uploader. I want to upload file and insert record into database (update if exist) It works as I want but uploader appears like there was an error

File upload correctly
Database insert (/update) record correctly.
Here is my code I use for upload file and database operation

[code]<?php
include(“…/config.php”);
$date=date(“Y-m-d”);
if (@$_REQUEST[“mode”] == “html5” || @$_REQUEST[“mode”] == “flash”) {
$filename = $_FILES[“file”][“name”];

$pfullname = explode(“.”,$filename);
$pext = $pfullname[0];

$result = mysql_query("SELECT nazev from voz_stroj_upload WHERE nazev =‘$pext’ ");
if (mysql_num_rows($result)>=1){//echo “tož hej”;
mysql_query(“UPDATE voz_stroj_upload SET pridal=‘jajsem12’ WHERE nazev=‘$pext’”);
echo “update ok”;
}
else{//echo “nieje”;
mysql_query(“insert into voz_stroj_upload (nazev,datum,pridal,souprava) values (‘$pext’,‘2008-01-01’,‘testovacifas’,2);”);
echo “insert ok”;
}

move_uploaded_file($_FILES["file"]["tmp_name"],"../soubory/fleet/".$filename);
print_r("{state: true, name:'".str_replace("'","\\'",$filename)."'}");

//mysql_query(“INSERT INTO voz_stroj_upload (nazev,datum,pridal,souprava) VALUES (‘$pext’,‘$date’,‘pokusna2’,‘987’)”) ;

}

if (@$_REQUEST[“mode”] == “html4”) {
if (@$_REQUEST[“action”] == “cancel”) {
print_r(“{state:‘cancelled’}”);
} else {
$filename = $_FILES[“file”][“name”];

$pfullname = explode(".",$filename);
$pext = $pfullname[0];

  move_uploaded_file($_FILES["file"]["tmp_name"], "../soubory/fleet/".$filename);
	print_r("{state: true, name:'".str_replace("'","\\'",$filename)."', size:".$_FILES["file"]["size"],filesize("../soubory/fleet/".$filename)."}");

//mysql_query(“INSERT INTO voz_stroj_upload (nazev,datum,pridal,souprava) VALUES (‘$pext’,‘$date’,‘pokusna2’,‘987’)”) ;
}
}
?>
[/code]

Hi

check your response, it should contain only json string, without any “update ok”, “insert ok”. if this not help - please provide direct link (or send it to support@dhtmlx.com)

Hi
That was the problem
Here is the code that woks

<?php

/*

if (mysql_num_rows($result)>=1){//echo "tož hej";
   mysql_query("UPDATE voz_stroj_upload SET pridal='jajsem12' WHERE nazev='$pext'");
   
  }
  else{//echo "nieje";
   mysql_query("insert into voz_stroj_upload (nazev,datum,pridal,souprava) values ('$pext','$datum','testovacifas',2);");
  
  }


HTML5/FLASH MODE

(MODE will detected on client side automaticaly. Working mode will passed to server as GET param "mode")

response format

if upload was good, you need to specify state=true and name - will passed in form.send() as serverName param
{state: 'true', name: 'filename'}

*/

if (@$_REQUEST["mode"] == "html5" || @$_REQUEST["mode"] == "flash") {
	$filename = $_FILES["file"]["name"];
	 move_uploaded_file($_FILES["file"]["tmp_name"],"../soubory/fleet/".$filename);
	print_r("{state: true, name:'".str_replace("'","\\'",$filename)."'}");
  
}

/*

HTML4 MODE

response format:

to cancel uploading
{state: 'cancelled'}

if upload was good, you need to specify state=true, name - will passed in form.send() as serverName param, size - filesize to update in list
{state: 'true', name: 'filename', size: 1234}

*/

if (@$_REQUEST["mode"] == "html4") {
	if (@$_REQUEST["action"] == "cancel") {
		print_r("{state:'cancelled'}");
	} else {
		$filename = $_FILES["file"]["name"];
		move_uploaded_file($_FILES["file"]["tmp_name"], "../soubory/fleet/".$filename);
		print_r("{state: true, name:'".str_replace("'","\\'",$filename)."', size:".$_FILES["file"]["size"],filesize("../soubory/fleet/".$filename)."}");
	}
}
   
  $datum=date("Y-m-d");
  include"../config.php";
  include"../a_rules.php";
  $uzivatel=$user_group[$u_handle]["name"];
  $pfullname = explode(".",@$filename);
  $pext = $pfullname[0]."^./soubory/fleet/".@$filename;
  $result = mysql_query("SELECT nazev from voz_stroj_upload WHERE nazev ='$pext' ");
  if (mysql_num_rows($result)>=1){
   mysql_query("UPDATE voz_stroj_upload SET pridal='$uzivatel', datum='$datum' WHERE nazev='$pext'");
   
  }
  else{
   mysql_query("insert into voz_stroj_upload (nazev,datum,pridal,souprava) values ('$pext','$datum','$uzivatel','172');");
  
  }



?>