Forums

PHP

This topic is locked

Upload file name being stored as tmp name

Posted 23 Apr 2002 22:09:04
1
has voted
23 Apr 2002 22:09:04 Eric Kaiser posted:
I have a two step update form. The first form updates the text data. The second form updates the image associated with the text. The problem I am having is with the second form, the image name is not being stored/passed correctly. I was using UD's PHP update function in conjunction with some hand code to upload the image. That code is below. I know it is storing the temp name generated by PHP, but I have no idea how to get the proper name stored. The upload works just fine.

And the code.....:

<?php


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

require("./../adodb/adodb.inc.php";
require("./../Connections/NewsDesigner.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
$UserID = $HTTP_COOKIE_VARS["UserID"];
// *** Edit Operations: declare Tables
$MM_editAction = $PHP_SELF;
if ($QUERY_STRING) {
$MM_editAction = $MM_editAction . "?" . $QUERY_STRING;
}

$MM_abortEdit = 0;
$MM_editQuery = "";
?><?php
// *** Update Record: set variables

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

// $MM_editConnection = $MM_NewsDesigner_STRING;
$MM_editTable = "UserPages";
$MM_editColumn = "PageID";
$MM_recordId = "" . $MM_recordId . "";
$MM_editRedirectUrl = "manage_folio.php?UserID=$UserID";
$MM_fieldsStr = "fupload|value";
$MM_columnsStr = "PageName|',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 = $NewsDesigner->Execute($MM_editQuery) or DIE($NewsDesigner->ErrorMsg());
if ($MM_editRedirectUrl)
{
header ("Location: $MM_editRedirectUrl";
}
}
}
?><?php
$UserID = $HTTP_COOKIE_VARS["UserID"]
?><?php
$rsPageInfo__MMColParam = "1";
if (isset($HTTP_GET_VARS["PageID"]))
{$rsPageInfo__MMColParam = $HTTP_GET_VARS["PageID"];}
?><?php
$rsPageInfo=$NewsDesigner->Execute("SELECT * FROM UserPages WHERE PageID = " . ($rsPageInfo__MMColParam) . "" or DIE($NewsDesigner->ErrorMsg());
$rsPageInfo_numRows=0;
$rsPageInfo__totalRows=$rsPageInfo->RecordCount();
?><?php
#upload the image
$file_dir = "/home/newspage/html/users/$UserID";
$file_url = "www.newspagedesigner.com/users/$UserID";
if ( isset( $fupload ) )
{
print "path: $fupload<br>\n";
print "name: $fupload_name<br>\n";
print "size: $fupload_size bytes<br>\n";
print "type: $fupload_type\n\n";


copy ( $fupload, "$file_dir/$fupload_name" or die ("couldn't copy";

#print "<img src=\"$file_url/$fupload_name\"><p>\n\n";
}

?>
<html>
<!-- #BeginTemplate "/Templates/home.dwt" -->
<head>
<!-- #BeginEditable "doctitle" -->
<title>News Page Designer</title>
<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="../styles.css" type="text/css">
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" text="#FFFFFF" link="#FFCC00" bgcolor="#333333">
<object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" codebase="download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="1600" height="62">
<param name=movie value="../flash/navbar.swf">
<param name=quality value=high>
<embed src="../flash/navbar.swf" quality=high pluginspage="www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="1600" height="62">
</embed>
</object>
<table width="800" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="140" valign="top" align="left">
<div align="left"></div>
</td>
<td width="660" bgcolor="#000000"><!-- #BeginEditable "center" -->
<form name="form1" method="POST" action="<?php echo $MM_editAction?>" enctype="multipart/form-data">
<table width="550" border="0" cellspacing="5" cellpadding="0">
<tr>
<td colspan="2" class="linkhead">Update Page</td>
</tr>
<tr>
<td width="158" align="right" class="text">Get New Picture:</td>
<td width="377">
<input type="file" name="fupload">
</td>
</tr>
<tr valign="middle">
<td width="158" align="right" class="text"> </td>
<td width="377">
<input type="submit" name="Submit" value="Upload New Page">
<a href="manage_folio.php?UserID=<?php echo $HTTP_COOKIE_VARS["UserID"]?>"><img src="images/skip.jpg" width="38" height="22" align="absmiddle" border="0"></a>
</td>
</tr>
<tr>
<td width="158" align="right" class="text"> </td>
<td width="377">
<?php echo $HTTP_COOKIE_VARS["UserID"]?>
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="true">
<input type="hidden" name="MM_recordId" value="<?php echo $rsPageInfo->Fields("PageID" ?>">
</form>
<!-- #EndEditable --></td>
</table>
<table width="1600" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="1600" height="89"><object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" codebase="download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="1600" height="300">
<param name=movie value="../flash/bottomstripe.swf">
<param name=quality value=high>
<embed src="../flash/bottomstripe.swf" quality=high pluginspage="www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="1600" height="300">
</embed>
</object></td>
</tr>
</table>
</body>
<!-- #EndTemplate -->
</html>
<?php
$rsPageInfo->Close();
?>

Replies

Replied 24 Apr 2002 16:10:14
24 Apr 2002 16:10:14 Eric Kaiser replied:
OK, I figured it out. Look at:
$MM_fieldsStr = "fupload|value";
$MM_columnsStr = "PageName|',none,''";

The problem was with the "fupload|value"; line. I changed it to:

$MM_fieldsStr = "fupload_name|value";
and it works just fine.

Reply to this topic