Forums

PHP

This topic is locked

Problem with PHP Upload File when using update rec

Posted 21 Dec 2001 03:23:07
1
has voted
21 Dec 2001 03:23:07 Paul Lacey posted:
Hello everyone,

I am having a problem with PHP Upload when trying to use it with update record behaviour. I get the following error:

You have an error in your SQL syntax near '' at line 1

Thanks to anyone who can help at all...

I have included the full page code below:

<?php


// Copyright (c) Interakt Online 2001
// www.interakt.ro/

require("./../../adodb/adodb.inc.php";
require("./../../Connections/K9_Data.php";
?><?php
// *** Edit Operations: declare Tables
$MM_editAction = $PHP_SELF;
if ($QUERY_STRING) {
$MM_editAction = $MM_editAction . "?" . $QUERY_STRING;
}

$MM_abortEdit = 0;
$MM_editQuery = "";
?><?php
# PHP Upload File v1.07
# Copyright 2001. Tim Green. All rights reserved.
# With many thanks to Massimo Foti and Waldo Smeets

if (isset($file)) {

# System Check Variables
$tgCHeader=getenv("CONTENT_LENGTH";
$tgRefPage=getenv("HTTP_REFERER";
$tg_FileSize=1*1024;

# Flags
$tg_OptionCheckSize=false;
$tg_UseRedirects=true;
$tg_UseErrorMsgs=false;
$tg_UpCopySuccess=false;
$tg_StatusMsg=false;

if ($tg_UseErrorMsgs) {
# Error Messages
$tg_ErrPrefix="?msg=";
$tg_OrigFileOver=$tg_ErrPrefix."Duplicate File Detected and Overwritten.";
$tg_UploadOpAbort=$tg_ErrPrefix."Duplicate Filename Encountered. Upload Aborted.";
$tg_CopyOpFailed=$tg_ErrPrefix."Unable to Copy File. Check Permissions of Target Directory.";
$tg_InvalidMIMEType=$tg_ErrPrefix."The Uploaded File was of an unknown, or unacceptable file type. Upload aborted.";
$tg_FileTooBig=$tg_ErrPrefix."The file exceeded the maximum allowable file size. Upload Aborted.";
$tg_MaliciousUpload=$tg_ErrPrefix."File Discrepancy Encountered. Upload Aborted.";
$tg_SuccessUpload=$tg_ErrPrefix."File Upload Successful.";
}

if (is_uploaded_file($file)) {
if (($tgCHeader <= $tg_FileSize)&&(filesize($file_name) <= $tg_FileSize)||(!$tg_OptionCheckSize)) {
$tg_Root=dirname($HTTP_SERVER_VARS["PATH_TRANSLATED"])."/";
$tg_Dir="../images/";
if ($tg_Dir=="/" {
$tg_Dir="";
}
$tg_File="$file_name";
$tg_OrigFile=$file;
$tg_Path="$tg_Root"."$tg_Dir"."$tg_File";
$tg_OptionCheckMIME=true;
$tg_cMimeVals="";

tg_OpenWin();

# Specifies the action to be taken if the file exists. overwrite, rename, abort
$tg_ExistsAction="overwrite";

# Check MIME type of file
if ($tg_OptionCheckMIME) {
$tgMIME="image/bmp|image/cgm|image/cmu-raster|image/g3fax|image/gif|image/ief|image/jpeg|image/naplps|image/pjpeg|image/png|image/targa|image/tiff|image/vnd.dwg|image/vnd.dxf|image/vnd.fpx|image/vnd.net.fpx|image/vnd.svf|image/x-cmu-raster|image/x-emf|image/x-jg|image/x-pict|image/x-png|image/x-portable-anymap|image/x-portable-bitmap|image/x-portable-graymap|image/x-portable-pixmap|image/x-rgb|image/x-tiff|image/x-win-bmp|image/x-xbitmap|image/x-xbm|image/x-xpixmap|image/x-wmf|image/x-windowdump";
if ($tgMIME!="custom" {
$acceptMIME=explode("|",$tgMIME);
} else {
$acceptMIME=explode(",",$tg_cMimeVals);
}
$testMIME=false;
for ($k=0; $k < count($acceptMIME); $k++) {
if ($acceptMIME[$k]==$file_type) {
$testMIME=true;
}
}
} else {
$testMIME=true;
}
if ($testMIME) {
# Now we need to check if the file exists in it's path
$testExists=file_exists($tg_Path);
if ($testExists) {
switch ($tg_ExistsAction) {
case "overwrite":
# Delete the original and copy over
unlink($tg_Path);
$tg_copyStatus=true;
$tg_StatusMsg=$tg_OrigFileOver;
break;
case "rename":
# Rename the Uploaded File and copy over
$unid=uniqid(rand(1,5));
$tg_NewName=$unid.$tg_File;
$tg_Path="$tg_Root"."$tg_Dir"."$tg_NewName";
$tg_copyStatus=true;
if ($tg_UseErrorMsgs) {
# $tg_File - contains original File Name
# $tg_NewName - contains New File Name
$tg_FileRenamed=$tg_ErrPrefix."The file $tg_File already exists. Uploaded file was renamed to $tg_NewName.";
} else {
$tg_FileRenamed="";
}
$tg_StatusMsg=$tg_FileRenamed;
break;
case "abort":
# stop processing upload
$tg_copyStatus=false;
$tg_StatusMsg=$tg_UploadOpAbort;
break;
}
} else {
$tg_copyStatus=true;
}
if ($tg_copyStatus) {
# Now we need to track the copy operation
$copyStatus=@copy("$tg_OrigFile","$tg_Path";
if(!$copyStatus) {
# Failed Copy Operation
if (!$tg_StatusMsg) {
$tg_StatusMsg=$tg_CopyOpFailed;
}

tg_CloseWin();
tg_RedirFail($tg_StatusMsg);

$tg_UpCopySuccess=false;
} else {
$tg_UpCopySuccess=true;
}
} else {
tg_CloseWin();
tg_RedirFail($tg_StatusMsg);
$tg_UpCopySuccess=false;
}
} else {
tg_CloseWin();
tg_RedirFail($tg_InvalidMIMEType);
$tg_UpCopySuccess=false;
}
} else {
# File is too big, go back to the referring page.
$tg_StatusMsg=$tg_FileTooBig;
$tg_ReferringPage=$tgRefPage.$tg_StatusMsg;
if ($tg_UseRedirects) {
header("Location: $tgReferringPage";
}
}
} else {
# If this part of the code has been reached then a possibly malicious upload has occurred
tg_RedirFail($tg_MaliciousUpload);
$tg_UpCopySuccess=false;
}
}

function tg_CloseWin() {
echo "<script language=\"Javascript\">\n";
echo "uploadWindow.close();\n";
echo "</script>\n";
}

function tg_RedirFail($msg) {
if ($GLOBALS["tg_UseRedirects"]) {
echo "<script language=\"Javascript\"> window.location=\"error.php$msg\"; </script>\n";
}
}

function tg_OpenWin() {
# Open the progress Window
echo "<script language=\"Javascript\">\n";
echo "var width=screen.width;\n";
echo "var height=screen.height;\n";
echo "var winwidth=280;\n";
echo "var winheight=100;\n";
echo "var top=(height-winheight)/2;\n";
echo "var left=(width-winwidth)/2;\n";
echo "uploadWindow=window.open(\"tgupprog.htm\",\"newWindow\",\"width=\"+winwidth+\",height=\"+winheight+\",left=\"+left+\",top=\"+top);\n";
echo "for (var loop=0;loop<20000;loop++) {\n";
echo "// pause loop\n";
echo "}\n";
echo "</script>\n";
}

if($tg_UpCopySuccess) {
# Successful Copy Operation
if ($tg_NewName=="" {
$file=$tg_File;
} else {
$file=$tg_NewName;
}
?><?php
// *** Update Record: set variables

if (isset($MM_update) && (isset($MM_recordId))) {

// $MM_editConnection = $MM_K9_Data_STRING;
$MM_editTable = "Feline_Articles";
$MM_editColumn = "ID";
$MM_recordId = "" . $MM_recordId . "";
$MM_editRedirectUrl = "";
$MM_fieldsStr = "file|value";
$MM_columnsStr = "Image|',none,''";

// create the $MM_fields and $MM_columns arrays
$MM_fields = Explode("|", $MM_fieldsStr);
$MM_columns = Explode("|", $MM_columnsStr);

// set the form values
for ($i=0; $i+1 < sizeof($MM_fields); ($i=$i+2)) {
$MM_fields[$i+1] = $$MM_fields[$i];
}

// append the query string to the redirect URL
if ($MM_editRedirectUrl && $QUERY_STRING && (strlen($QUERY_STRING) > 0)) {
$MM_editRedirectUrl .= ((strpos($MM_editRedirectUrl, '?') == false)?"?":"&" . $QUERY_STRING;
}
}
?><?php
// *** Update Record: construct a sql update statement and execute it

if (isset($MM_update) && (isset($MM_recordId))) {

// create the sql update statement
$MM_editQuery = "update " . $MM_editTable . " set ";
for ( $i=0; $i+1 < sizeof($MM_fields); ($i=$i+2))
{
$formVal = $MM_fields[$i+1];
$MM_typesArray = Explode(",", $MM_columns[$i+1]);
$delim = ($MM_typesArray[0] != "none" ? $MM_typesArray[0] : "";
$altVal = ($MM_typesArray[1] != "none" ? $MM_typesArray[1] : "";
$emptyVal = ($MM_typesArray[2] != "none" ? $MM_typesArray[2] : "";
if ($formVal == "" || !isset($formVal))
{
$formVal = $emptyVal;
}
else
{
if ($altVal != ""
{
$formVal = $altVal;
}
else if ($delim == "'"
{ // do not escape quotes in PHP4
$formVal = "'" .$formVal . "'";
}
else
{
$formVal = $delim . $formVal . $delim;
}
}
if ($i != 0)
{
$MM_editQuery = $MM_editQuery . ", " . $MM_columns[$i] . " = " . $formVal;
}
else
{
$MM_editQuery = $MM_editQuery . $MM_columns[$i] . " = " . $formVal;
}
}

$MM_editQuery = $MM_editQuery . " where " . $MM_editColumn . " = " . $MM_recordId;

if ($MM_abortEdit != 1)
{
// execute the insert
$queryrs = $K9_Data->Execute($MM_editQuery) or DIE($K9_Data->ErrorMsg());
if ($MM_editRedirectUrl)
{
header ("Location: $MM_editRedirectUrl";
}
}
}
?><?php
$Recordset1__MMColParam = "1";
if (isset($HTTP_GET_VARS["ID"]))
{$Recordset1__MMColParam = $HTTP_GET_VARS["ID"];}
?><?php
if (!$tg_StatusMsg) {
$tg_StatusMsg=$tg_SuccessUpload;
}

tg_CloseWin();
if ($tg_UseRedirects) {
echo "<script language=\"Javascript\"> window.location=\"popupdated.php$tg_StatusMsg\"; </script>\n";
} else {
$msg=$tg_StatusMsg;
}
}
?><?php
$Recordset1=$K9_Data->Execute("SELECT * FROM Feline_Articles WHERE ID = " . ($Recordset1__MMColParam) . "" or DIE($K9_Data->ErrorMsg());
$Recordset1_numRows=0;
$Recordset1__totalRows=$Recordset1->RecordCount();
?>
<html>
<head>
<title>Update Image</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form ACTION="<?php echo $MM_editAction?>" name="form1" enctype="multipart/form-data" method="POST">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Select a file using
the browse button below:</font> <br>
<input type="file" name="file">
<br>
<br>
<font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="image" src="update.gif" onClick="SubmitForm();return false;" name="image" width="67" height="17">
</font>
<input type="hidden" name="MM_update" value="true">
<input type="hidden" name="MM_recordId" value="<?php echo $Recordset1->Fields("ID" ?>">
</form>
</body>
</html>
<?php
$Recordset1->Close();
?>

Replies

Replied 21 Dec 2001 11:24:29
21 Dec 2001 11:24:29 Tim Green replied:
This issue would appear to occur because you are directly using the file upload field in your update behaviour.

As it is a form field UltraDev will let you do this, but the reason that the error occurs is that this variable after upload will actually contain binary remnants of the file.

To get around this, insert inside your form a hidden field, and name it the same as your file field, then add '_name' to the end of it. So with this page you would have:-

<input type="hidden" name="file_name">

Now, reapply your update record server behaviour and change the 'file' form field to 'ignore', and change the file_name field to point to the relative column in your database.

The update should now work.

Hope this helps.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 17 Jan 2002 12:54:09
17 Jan 2002 12:54:09 Zvonimir Gembec replied:
I also have problems with that...but unforunaly this is not helping...
after that i again has error:
You have an error in your SQL syntax near '' at line 1<img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle>

here is source:
&lt;?php


// Copyright (c) Interakt Online 2001
// www.interakt.ro/

require("./../adodb/adodb.inc.php";
require("./../Connections/connCosmic.php";
?&gt;
&lt;?php
// *** Edit Operations: declare Tables
$MM_editAction = $PHP_SELF;
if ($QUERY_STRING) {
$MM_editAction = $MM_editAction . "?" . $QUERY_STRING;
}

$MM_abortEdit = 0;
$MM_editQuery = "";
?&gt;
&lt;?php
# PHP Upload File v1.07
# Copyright 2001. Tim Green. All rights reserved.
# With many thanks to Massimo Foti and Waldo Smeets

if (isset($file)) {

# System Check Variables
$tgCHeader=getenv("CONTENT_LENGTH";
$tgRefPage=getenv("HTTP_REFERER";
$tg_FileSize=12*1024;

# Flags
$tg_OptionCheckSize=true;
$tg_UseRedirects=true;
$tg_UseErrorMsgs=true;
$tg_UpCopySuccess=false;
$tg_StatusMsg=false;

if ($tg_UseErrorMsgs) {
# Error Messages
$tg_ErrPrefix="?msg=";
$tg_OrigFileOver=$tg_ErrPrefix."Duplicate File Detected and Overwritten.";
$tg_UploadOpAbort=$tg_ErrPrefix."Duplicate Filename Encountered. Upload Aborted.";
$tg_CopyOpFailed=$tg_ErrPrefix."Unable to Copy File. Check Permissions of Target Directory.";
$tg_InvalidMIMEType=$tg_ErrPrefix."The Uploaded File was of an unknown, or unacceptable file type. Upload aborted.";
$tg_FileTooBig=$tg_ErrPrefix."The file exceeded the maximum allowable file size. Upload Aborted.";
$tg_MaliciousUpload=$tg_ErrPrefix."File Discrepancy Encountered. Upload Aborted.";
$tg_SuccessUpload=$tg_ErrPrefix."File Upload Successful.";
}

if (is_uploaded_file($file)) {
if (($tgCHeader &lt;= $tg_FileSize)&&(filesize($file_name) &lt;= $tg_FileSize)||(!$tg_OptionCheckSize)) {
$tg_Root=dirname($HTTP_SERVER_VARS["PATH_TRANSLATED"])."/";
$tg_Dir="../localita/";
if ($tg_Dir=="/" {
$tg_Dir="";
}
$tg_File="$file_name";
$tg_OrigFile=$file;
$tg_Path="$tg_Root"."$tg_Dir"."$tg_File";
$tg_OptionCheckMIME=true;
$tg_cMimeVals="";

tg_OpenWin();

# Specifies the action to be taken if the file exists. overwrite, rename, abort
$tg_ExistsAction="overwrite";

# Check MIME type of file
if ($tg_OptionCheckMIME) {
$tgMIME="image/bmp|image/cgm|image/cmu-raster|image/g3fax|image/gif|image/ief|image/jpeg|image/naplps|image/pjpeg|image/png|image/targa|image/tiff|image/vnd.dwg|image/vnd.dxf|image/vnd.fpx|image/vnd.net.fpx|image/vnd.svf|image/x-cmu-raster|image/x-emf|image/x-jg|image/x-pict|image/x-png|image/x-portable-anymap|image/x-portable-bitmap|image/x-portable-graymap|image/x-portable-pixmap|image/x-rgb|image/x-tiff|image/x-win-bmp|image/x-xbitmap|image/x-xbm|image/x-xpixmap|image/x-wmf|image/x-windowdump";
if ($tgMIME!="custom" {
$acceptMIME=explode("|",$tgMIME);
} else {
$acceptMIME=explode(",",$tg_cMimeVals);
}
$testMIME=false;
for ($k=0; $k &lt; count($acceptMIME); $k++) {
if ($acceptMIME[$k]==$file_type) {
$testMIME=true;
}
}
} else {
$testMIME=true;
}
if ($testMIME) {
# Now we need to check if the file exists in it's path
$testExists=file_exists($tg_Path);
if ($testExists) {
switch ($tg_ExistsAction) {
case "overwrite":
# Delete the original and copy over
unlink($tg_Path);
$tg_copyStatus=true;
$tg_StatusMsg=$tg_OrigFileOver;
break;
case "rename":
# Rename the Uploaded File and copy over
$unid=uniqid(rand(1,5));
$tg_NewName=$unid.$tg_File;
$tg_Path="$tg_Root"."$tg_Dir"."$tg_NewName";
$tg_copyStatus=true;
if ($tg_UseErrorMsgs) {
# $tg_File - contains original File Name
# $tg_NewName - contains New File Name
$tg_FileRenamed=$tg_ErrPrefix."The file $tg_File already exists. Uploaded file was renamed to $tg_NewName.";
} else {
$tg_FileRenamed="";
}
$tg_StatusMsg=$tg_FileRenamed;
break;
case "abort":
# stop processing upload
$tg_copyStatus=false;
$tg_StatusMsg=$tg_UploadOpAbort;
break;
}
} else {
$tg_copyStatus=true;
}
if ($tg_copyStatus) {
# Now we need to track the copy operation
$copyStatus=@copy("$tg_OrigFile","$tg_Path";
if(!$copyStatus) {
# Failed Copy Operation
if (!$tg_StatusMsg) {
$tg_StatusMsg=$tg_CopyOpFailed;
}

tg_CloseWin();
tg_RedirFail($tg_StatusMsg);

$tg_UpCopySuccess=false;
} else {
$tg_UpCopySuccess=true;
}
} else {
tg_CloseWin();
tg_RedirFail($tg_StatusMsg);
$tg_UpCopySuccess=false;
}
} else {
tg_CloseWin();
tg_RedirFail($tg_InvalidMIMEType);
$tg_UpCopySuccess=false;
}
} else {
# File is too big, go back to the referring page.
$tg_StatusMsg=$tg_FileTooBig;
$tg_ReferringPage=$tgRefPage.$tg_StatusMsg;
if ($tg_UseRedirects) {
header("Location: $tgReferringPage";
}
}
} else {
# If this part of the code has been reached then a possibly malicious upload has occurred
tg_RedirFail($tg_MaliciousUpload);
$tg_UpCopySuccess=false;
}
}

function tg_CloseWin() {
echo "&lt;script language=\"Javascript\"&gt;\n";
echo "uploadWindow.close();\n";
echo "&lt;/script&gt;\n";
}

function tg_RedirFail($msg) {
if ($GLOBALS["tg_UseRedirects"]) {
echo "&lt;script language=\"Javascript\"&gt; window.location=\"upload_slike_fail.php$msg\"; &lt;/script&gt;\n";
}
}

function tg_OpenWin() {
# Open the progress Window
echo "&lt;script language=\"Javascript\"&gt;\n";
echo "var width=screen.width;\n";
echo "var height=screen.height;\n";
echo "var winwidth=280;\n";
echo "var winheight=100;\n";
echo "var top=(height-winheight)/2;\n";
echo "var left=(width-winwidth)/2;\n";
echo "uploadWindow=window.open(\"tgupprog.htm\",\"newWindow\",\"width=\"+winwidth+\",height=\"+winheight+\",left=\"+left+\",top=\"+top);\n";
echo "for (var loop=0;loop&lt;20000;loop++) {\n";
echo "// pause loop\n";
echo "}\n";
echo "&lt;/script&gt;\n";
}

if($tg_UpCopySuccess) {
# Successful Copy Operation
if ($tg_NewName=="" {
$file=$tg_File;
} else {
$file=$tg_NewName;
}
?&gt;
&lt;?php
// *** Update Record: set variables

if (isset($MM_update) && (isset($MM_recordId))) {

// $MM_editConnection = $MM_connCosmic_STRING;
$MM_editTable = "slike";
$MM_editColumn = "ids";
$MM_recordId = "" . $MM_recordId . "";
$MM_editRedirectUrl = "";
$MM_fieldsStr = "ime_mjesto|value|file_name|value";
$MM_columnsStr = "ime_mjesto|',none,''|filename|',none,''";

// create the $MM_fields and $MM_columns arrays
$MM_fields = Explode("|", $MM_fieldsStr);
$MM_columns = Explode("|", $MM_columnsStr);

// set the form values
for ($i=0; $i+1 &lt; sizeof($MM_fields); ($i=$i+2)) {
$MM_fields[$i+1] = $$MM_fields[$i];
}

// append the query string to the redirect URL
if ($MM_editRedirectUrl && $QUERY_STRING && (strlen($QUERY_STRING) &gt; 0)) {
$MM_editRedirectUrl .= ((strpos($MM_editRedirectUrl, '?') == false)?"?":"&" . $QUERY_STRING;
}
}
?&gt;
&lt;?php
// *** Update Record: construct a sql update statement and execute it

if (isset($MM_update) && (isset($MM_recordId))) {

// create the sql update statement
$MM_editQuery = "update " . $MM_editTable . " set ";
for ( $i=0; $i+1 &lt; sizeof($MM_fields); ($i=$i+2))
{
$formVal = $MM_fields[$i+1];
$MM_typesArray = Explode(",", $MM_columns[$i+1]);
$delim = ($MM_typesArray[0] != "none" ? $MM_typesArray[0] : "";
$altVal = ($MM_typesArray[1] != "none" ? $MM_typesArray[1] : "";
$emptyVal = ($MM_typesArray[2] != "none" ? $MM_typesArray[2] : "";
if ($formVal == "" || !isset($formVal))
{
$formVal = $emptyVal;
}
else
{
if ($altVal != ""
{
$formVal = $altVal;
}
else if ($delim == "'"
{ // do not escape quotes in PHP4
$formVal = "'" .$formVal . "'";
}
else
{
$formVal = $delim . $formVal . $delim;
}
}
if ($i != 0)
{
$MM_editQuery = $MM_editQuery . ", " . $MM_columns[$i] . " = " . $formVal;
}
else
{
$MM_editQuery = $MM_editQuery . $MM_columns[$i] . " = " . $formVal;
}
}

$MM_editQuery = $MM_editQuery . " where " . $MM_editColumn . " = " . $MM_recordId;

if ($MM_abortEdit != 1)
{
// execute the insert
$queryrs = $connCosmic-&gt;Execute($MM_editQuery) or DIE($connCosmic-&gt;ErrorMsg());
if ($MM_editRedirectUrl)
{
header ("Location: $MM_editRedirectUrl";
}
}
}
?&gt;
&lt;?php
$rsImages__MMColParam = "1";
if (isset($HTTP_GET_VARS["rb"]))
{$rsImages__MMColParam = $HTTP_GET_VARS["rb"];}
?&gt;
&lt;?php
if (!$tg_StatusMsg) {
$tg_StatusMsg=$tg_SuccessUpload;
}

tg_CloseWin();
if ($tg_UseRedirects) {
echo "&lt;script language=\"Javascript\"&gt; window.location=\"upload_slike_succ.php$tg_StatusMsg\"; &lt;/script&gt;\n";
} else {
$msg=$tg_StatusMsg;
}
}
?&gt;
&lt;?php
$rsImages=$connCosmic-&gt;Execute("SELECT ids, ime_mjesto, filename FROM slike WHERE ids = " . ($rsImages__MMColParam) . "" or DIE($connCosmic-&gt;ErrorMsg());
$rsImages_numRows=0;
$rsImages__totalRows=$rsImages-&gt;RecordCount();
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Upload slika&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"&gt;
&lt;link rel="stylesheet" href="nit.css" type="text/css"&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF" &gt;
&lt;FORM ACTION="&lt;?php echo $MM_editAction?&gt;" enctype="multipart/form-data"
name="form1" method="POST"&gt;
&lt;table width="100%" border="0"&gt;
&lt;tr&gt;
&lt;td colspan="3" class="polaris1"&gt;&lt;font size="5" face="Verdana, Arial, Helvetica, sans-serif"&gt;&lt;b&gt;Upload
foto&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
&lt;td colspan="2"&gt;
&lt;div align="right"&gt;
&lt;p class="polaris1"&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="5"&gt;
&lt;hr&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="5"&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="30%"&gt;
&lt;p&gt;&lt;b&gt;Nome di localita&lt;/b&gt;:&lt;/p&gt;
&lt;p&gt;
&lt;select name="ime_mjesto"&gt;
&lt;option selected&gt; &lt;/option&gt;
&lt;?php
if ($rsImages__totalRows &gt; 0){
$rsImages__index=0;
$rsImages-&gt;MoveFirst();
WHILE ($rsImages__index &lt; $rsImages__totalRows){
?&gt;
&lt;OPTION VALUE="&lt;?php echo $rsImages-&gt;Fields("ime_mjesto"?&gt;"&gt;
&lt;?php echo $rsImages-&gt;Fields("ime_mjesto";?&gt;
&lt;/OPTION&gt;
&lt;?php
$rsImages-&gt;MoveNext();
$rsImages__index++;
}
$rsImages__index=0;
$rsImages-&gt;MoveFirst();
}
?&gt;
&lt;/select&gt;
&lt;input type="hidden" name="file_name"&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/p&gt;
&lt;/td&gt;
&lt;td width="1%"&gt;&nbsp;&nbsp;&lt;/td&gt;
&lt;td width="31%"&gt;
&lt;div align="center"&gt;
&lt;input type="file" name="file"&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td width="0%" valign="top"&gt;&nbsp;&nbsp;&lt;/td&gt;
&lt;td width="38%" valign="top"&gt;
&lt;p&gt;&nbsp;&nbsp;&nbsp;Ako se lijevo od ovog texta pojavi slika, tada slika
za ovaj &#269;lanak ve&#263; postoji, no ako je ovo novi &#269;lank, to ne&#263;e biti slu&#269;aj.
Ako &#382;elite staviti novu sliku, &quot;BROWSE&quot;, nadjite sliku pa
&quot;UPLOAD&quot;... i neka ne bude ve&#263;a od 10 - 12 Kb.. (72 dpi /200
x 300 pixela cca). Ako ne &#382;elite uploadati sliku sliku, kliknite na
&quot;GOTOVO&quot;!&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="30%"&gt;&nbsp;&lt;/td&gt;
&lt;td width="1%"&gt;&nbsp;&lt;/td&gt;
&lt;td width="31%" valign="top"&gt;&nbsp;&lt;/td&gt;
&lt;td width="0%" valign="top"&gt;&nbsp;&lt;/td&gt;
&lt;td width="38%" valign="top"&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td width="30%"&gt;
&lt;div align="center"&gt;
&lt;input type="submit" name="Submit" value="Upload"&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;td width="1%"&gt;&nbsp;&lt;/td&gt;
&lt;td width="31%" valign="top"&gt;&nbsp;&lt;/td&gt;
&lt;td width="0%" valign="top"&gt;&nbsp;&lt;/td&gt;
&lt;td width="38%" valign="top"&gt;
&lt;div align="center"&gt; &lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input type="hidden" name="MM_update" value="true"&gt;
&lt;input type="hidden" name="MM_recordId" value="&lt;?php echo $rsImages-&gt;Fields("ids" ?&gt;"&gt;
&lt;/form&gt;
&lt;hr&gt;
&lt;div align="center"&gt;
&lt;p&gt;&lt;span class="nit"&gt;&lt;br&gt;
&lt;font size="1"&gt;&copy; &lt;a href="www.mojsite.com"&gt;Mojsite.com&lt;/a&gt; 2001.&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;?php
$rsImages-&gt;Close();
?&gt;
<b></b>

Replied 18 Jan 2002 08:59:38
18 Jan 2002 08:59:38 Zvonimir Gembec replied:
I think i find a solution!!!!

In recordset, paullacey should change

($Recordset1__MMColParam) in

$rsImages=$connCosmic-&gt;Execute("SELECT ids, ime_mjesto, filename FROM slike WHERE ids = " . $ID . "" or DIE($connCosmic-&gt;ErrorMsg());

and in my recordset it have to look like:

$rsImages=$connCosmic-&gt;Execute("SELECT ids, ime_mjesto, filename FROM slike WHERE ids = " . $rb . "" or DIE($connCosmic-&gt;ErrorMsg());

and it works!!!!
Looks like something is messed up with recordset, but when you pick up an url parametar, it works...

Maybe I should make sql querry som other way??

Who knows...whatewer, IT WORKS!!! That is mot important to me <img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>

Replied 19 Jan 2002 02:48:28
19 Jan 2002 02:48:28 Tim Green replied:
Thanks for posting the feeback. Glad you got it to work <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 20 Jan 2002 17:24:08
20 Jan 2002 17:24:08 Zvonimir Gembec replied:
Tim, in future versions you defenetly have to include "old_file_cleaning"!! I have to modify code because, if you, in some odd reason, must replace old image with new one with new name, offcourse, old image stays on disc!!! But if you put that code :
&lt;?php
// brisanje starog filea (ako je ime drugo)
if ($rsImages-&gt;Fields("filename" != $file_name) {
if (file_name != "" {
unlink($tg_Dir . $rsImages-&gt;Fields("filename");
}
} ?&gt;
somewhere before ...update record, it will clean old images, in old i mean, images that was in that place before new upload!!!

And second thing, "if_file_is_to_big" method shold be more adjustabile, for example: you should may redirect to error page too, not just referrer page!

PS: thanx for answer! This is great extension! I am waiting your shoping cart to be aviliabile

gemby

Replied 20 Jan 2002 22:12:00
20 Jan 2002 22:12:00 Tim Green replied:
Thanks for your comments, I will indeed take them on board for the next version <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

And you won't have to wait for too much longer now for IntelliCART either <img src=../images/dmxzone/forum/icon_smile_wink.gif border=0 align=middle>

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 24 Jan 2002 09:47:40
24 Jan 2002 09:47:40 Zvonimir Gembec replied:
Good bless you!!!
<img src=../images/dmxzone/forum/icon_smile_big.gif border=0 align=middle>

Replied 30 Jan 2002 15:51:04
30 Jan 2002 15:51:04 enquest enquest1 replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
This issue would appear to occur because you are directly using the file upload field in your update behaviour.

As it is a form field UltraDev will let you do this, but the reason that the error occurs is that this variable after upload will actually contain binary remnants of the file.

To get around this, insert inside your form a hidden field, and name it the same as your file field, then add '_name' to the end of it. So with this page you would have:-

&lt;input type="hidden" name="file_name"&gt;

Now, reapply your update record server behaviour and change the 'file' form field to 'ignore', and change the file_name field to point to the relative column in your database.

The update should now work.

Hope this helps.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
I did what is stated in the above quote.
However the upload doesn’t work and I don’t know why.
I’m using the following procedure.
When coming to the upload update page in the url is ?code=bs01. So this is ok

InsertForm with upload field. (name=file)
Insert the upload script. Setting -&gt; use redirect on, 100 k upload etc…
Until here all works
Create a hidden field
(name=file_name)
and use the update script pointing ad file_name. Just as Tim says

The error I get is brief before it sends me to the fail page. The uploading doesn’t either work.
Warning: Unlink failed (Permission denied) in C:\apache\htdocs\nsteen\inhoud\upload.php on line 92

The code says at line from 90
# Delete the original and copy over
unlink($tg_Path);
$tg_copyStatus=true;
$tg_StatusMsg=$tg_OrigFileOver;
break;

I did try it under little differences but it still doesn’t work. Remade the form servel time’s etc… Still no luck. What to do?
I didn’t use any unlink command so the file name that is uploaded is a different name. It just should update the database at code BS01 …
Further when I don’t use the update script then there is no problem with uploading and overwriting a file. So permission denied ????

I either find the piece of code Gemby pointed at.


Thanxs



Replied 30 Jan 2002 22:21:10
30 Jan 2002 22:21:10 Tim Green replied:
unlink() is the command issued to delete your temporarily uploaded file once it has been copied to it's final location.

If you get this error, then it basically means that you do not have permissions to delete a file, but if that's the case, then you can't upload a file either.

The problem is, that if the upload works WITHOUT the update behaviour, and then breaks when you apply the update behaviour, then, essentially you are doing something wrong as neither behaviour properly interact in a way to stop this functionality.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 31 Jan 2002 01:31:10
31 Jan 2002 01:31:10 Zvonimir Gembec replied:
I would try only update behavior first, if it works, remove update behavior, put upload behavior, put update behavior same way you did last time, and try again. Check if all files have same uid!!?! Btw, in what OS are you trying to do that? In same Windows/PHP combinations unlink won't work!!!If is on Unix/Linux enviroment it should work...try check premissions of folder you are uploading in (is it 777) (chmod 777 foldername)....
Sometimes is helpfull if you just switch off computer, think it over and continue next day (this is helpful for me) <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>

gemby

Replied 31 Jan 2002 09:23:49
31 Jan 2002 09:23:49 enquest enquest1 replied:
Why wouldn't unlink work? Unlink always worked with no problem. I am using win 2000 and latest version off phakt. And an up to date PHP

Replied 31 Jan 2002 14:49:21
31 Jan 2002 14:49:21 enquest enquest1 replied:
You sure it isn't a bug with in the upload script with phakt 1.1.3. . Because I keep getting the error no matter what I do. Tested now on locolhost as well as on a linux server. But keep ketting the same result. And it is to hard to make a it. One can not do that many things wrong. Besides I did it before with no problem! but now I keep ketting the error.

Thanxs

Replied 01 Feb 2002 13:37:54
01 Feb 2002 13:37:54 Tim Green replied:
Nope, it isn't a bug. I've used it with great success just recently.



Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Reply to this topic