View Full Version : Upload image file not working
roby258376
04-09-2009, 05:14 AM
I am having a problem getting images to upload.
I am trying to change my "edit profile" page to allow users to upload a new image. I have followed the tutorial, but it says in the last step to open up the "WA Update Record" server behaviour. I do not have that server behaviour, the only thing I have that comes close is "Update Record (WAATKUpdateForm, members, members). I created the form with Data Assist so I'm not sure why I don't have the right server behaviour.
So, my questions are:
1) does DFP only work with Data Assist? or is it supposed to work with any update form?
2) is there something I'm missing that allows a new file to be uploaded?
My update page works great, for every element except the image. Without adding the DFP functionality, I can change the name of the image file, and it updates in the database, but I cannot of course, upload a new image.
When I try to add the DFP functionality to upload an image, it deleted the information currently in the database and doesn't upload the picture.
Any help would be appreciated, I'm tearing my hair out.
p.s. I did add the debug info to the page, but since I'm new to this, it doesn't really help me.
Ray Borduin
04-09-2009, 07:14 AM
It works with DataAssist (or hand code)... some upload extensions don't allow you to specify values from bindings, which prevents them from working properly without hand code... The page was probably created with SecurityAssist and not DataAssist... you may need to reapply the server behavior because securityassist uses the standard DW Insert/Update which don't work properly with file uploading.
roby258376
04-09-2009, 07:21 AM
Thank Ray, I've been having all sorts of problems with DataAssist, so you could be right that the page I'm updating from was created with Security Assist.
Can you give me some instruction on how to reapply the right server behaviour to get this to work?
Ray Borduin
04-09-2009, 07:24 AM
Open the existing server behavior for insert or update and copy the redirect page.
Then remove the server behavior and apply the corresponding insert or update server behavior from dataassist pasting in the same redirect page and using the bindings to set the values of the database columns including your upload field.
roby258376
04-09-2009, 08:21 AM
Again Ray, thank you for your quick reply.
So, I followed your instructions, removed the old server upload behaviour and added a Data Assist one.
I then followed the instructions in the tutorial and everything works fine except for the file upload. The images are not being uploaded and renamed properly, to the folder I designated, and the name of the file, in the database field is not updating.
Any suggestions? Any help is appreciated.
Ray Borduin
04-09-2009, 10:38 AM
Well if the file isn't uploaded properly then of course other things may not work, so concentrate on that.
What exactly happens? Do the files get uploaded at all? Most likely this is a file permissions issue.
roby258376
04-09-2009, 12:52 PM
Well, it seems that prior to removing the server behaviour that was generated by Security Assist, and replacing it with the one from site Assist, the image was being uploaded and renamed in the folder that I designated in the Digital File Pro Wizard. However, the database field was not being updated with the file name information, so nothing was showing up on my pages for the image.
Now that I've deleted the Security Assist server behaviour and generated one with Site Assist, I'm not getting an update to the database and the image is not being uploaded either. All the other database fields update, but when I browse for a new image and then click submit. The page reloads and the new information is no where to be found.
I've tried setting permission but that doesn't seem to be helping either.
Ray Borduin
04-09-2009, 01:31 PM
OK, so maybe the file upload code was placed below the database insert or update code, so that it hasn't been uploaded at the time of the database update and then you redirect and the upload code never runs... that seems possible based on your description.
roby258376
04-09-2009, 01:55 PM
I checked and it appears that the upload code is prior to the update code. but I'm including that part of the page below. If you can see anything out of place, well, let's just say, you'll see it WAY before I do :)
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if(isset($_POST["Update_x"])){
WA_DFP_UploadFile("WA_UploadResult1", "pictureFile", "".((isset($_POST["picture"]))?$_POST["picture"]:"") ."", "../images/members/", "".$row_WAATKmembers['lastName'] ."", "2", "[FileName]_[Increment]", "0", "true", "150", "0");
}
?>
<?php
// WA Application Builder Update
if (isset($_POST["Update_x"])) // Trigger
{
$WA_connection = $members;
$WA_table = "members";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "UserID";
$WA_fieldNamesStr = "lastName|firstName|member_status|company|title|add ress|city|province_state|pc_zip|telephone|fax|cell _phone|email|url|business_category|picture";
$WA_fieldValuesStr = "".((isset($_POST["lastName"]))?$_POST["lastName"]:"") ."" . "|" . "".((isset($_POST["firstName"]))?$_POST["firstName"]:"") ."" . "|" . "".((isset($_POST["member_status"]))?$_POST["member_status"]:"") ."" . "|" . "".((isset($_POST["company"]))?$_POST["company"]:"") ."" . "|" . "".((isset($_POST["title"]))?$_POST["title"]:"") ."" . "|" . "".((isset($_POST["address"]))?$_POST["address"]:"") ."" . "|" . "".((isset($_POST["city"]))?$_POST["city"]:"") ."" . "|" . "".((isset($_POST["province_state"]))?$_POST["province_state"]:"") ."" . "|" . "".((isset($_POST["pc_zip"]))?$_POST["pc_zip"]:"") ."" . "|" . "".((isset($_POST["telephone"]))?$_POST["telephone"]:"") ."" . "|" . "".((isset($_POST["fax"]))?$_POST["fax"]:"") ."" . "|" . "".((isset($_POST["cell_phone"]))?$_POST["cell_phone"]:"") ."" . "|" . "".((isset($_POST["email"]))?$_POST["email"]:"") ."" . "|" . "".((isset($_POST["url"]))?$_POST["url"]:"") ."" . "|" . "".((isset($_POST["business_category"]))?$_POST["business_category"]:"") ."" . "|" . "".$WA_DFP_UploadStatus["WA_UploadResult1"]["serverFileName"] ."";
$WA_columnTypesStr = "',none,''|',none,''|',none,''|',none,''|',none,''| ',none,''|',none,''|',none,''|',none,''|',none,''| ',none,''|',none,''|',none,''|',none,''|',none,''| ',none,''";
$WA_comparisonStr = "=|=|=|=|=|=|=|=|=|=|=|=|=|=|=|=";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_where_fieldValuesStr = "".$_SESSION['UserID'] ."";
$WA_where_columnTypesStr = "none,none,NULL";
$WA_where_comparisonStr = "=";
$WA_where_fieldNames = explode("|", $WA_indexField);
$WA_where_fieldValues = explode("|", $WA_where_fieldValuesStr);
$WA_where_columns = explode("|", $WA_where_columnTypesStr);
$WA_where_comparisons = explode("|", $WA_where_comparisonStr);
$WA_connectionDB = $database_members;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues, $WA_where_comparisons );
$WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
Ray Borduin
04-09-2009, 02:29 PM
It looks correct to me. But your statement:
"it seems that prior to removing the server behaviour that was generated by Security Assist, and replacing it with the one from site Assist, the image was being uploaded and renamed in the folder that I designated in the Digital File Pro Wizard"
must not be correct then... I don't see how code after the upload could effect code before.
Is the recordset : WAATKmembers above both of these?
roby258376
04-09-2009, 03:37 PM
Yes it is above it. The code I posted is the last on the page prior to the html starting.
I can't say why the images uploaded before, the names were not showing up at all in the database so I figured it wasn't working, but when I checked the image folder, after posting here, there were several renamed images, renamed with increment as outlined in the tutorial. But it's not uploading them at all now.
Any other ideas?
Ray Borduin
04-09-2009, 03:59 PM
I'd debug the upload.... so add code and change:
if(isset($_POST["Update_x"])){
WA_DFP_UploadFile("WA_UploadResult1", "pictureFile", "".((isset($_POST["picture"]))?$_POST["picture"]:"") ."", "../images/members/", "".$row_WAATKmembers['lastName'] ."", "2", "[FileName]_[Increment]", "0", "true", "150", "0");
}
to:
if(isset($_POST["Update_x"])){
WA_DFP_UploadFile("WA_UploadResult1", "pictureFile", "".((isset($_POST["picture"]))?$_POST["picture"]:"") ."", "../images/members/", "".$row_WAATKmembers['lastName'] ."", "2", "[FileName]_[Increment]", "0", "true", "150", "0");
var_dump($WA_DFP_UploadStatus["WA_UploadResult1"]);
die();
}
That should tell you about the file that was uploaded including any errors.
roby258376
04-09-2009, 04:30 PM
When I add that code, and reload the page, I get:
array(15) { ["statusCode"]=> int(-1) ["errorMessage"]=> string(0) "" ["clientFileName"]=> string(22) "myphoto.jpg" ["fileExtension"]=> string(3) "jpg" ["serverFileName"]=> string(0) "" ["serverDirectory"]=> string(1) "/" ["contentType"]=> string(10) "image/jpeg" ["fileWasOverwritten"]=> bool(false) ["fileWasSkipped"]=> bool(false) ["fileWasRenamed"]=> bool(false) ["fileSize"]=> int(6945) ["isImage"]=> bool(true) ["imageWidth"]=> int(125) ["imageHeight"]=> int(188) ["uploadFolder"]=> bool(false) }
Ray Borduin
04-09-2009, 05:09 PM
That implies that the image was uploaded... but you are sure it isn't?
Ray Borduin
04-09-2009, 05:12 PM
It looks liek it tred to upload to the root directory... is that where you are looking for the image?
roby258376
04-09-2009, 08:08 PM
Hi Ray,
I checked every directory on the root and the upload isn't anywhere to be found. The image is supposed to upload to images/members/ but it's not only not there, it's not anywhere.
As well the database isn't updating either.
So, what next?
Robin
Ray Borduin
04-10-2009, 07:24 AM
I don't know why I didn't notice it before, but your status code is -1.
I found this in the include file for digital file pro:
Upload status codes and error messages:
-1 Trigger did not run
0 File not uploaded
1 All is well, upload processed
10 failed image file type check
11 failed image width limit
12 failed image height limit
20 failed file size limit
30 upload skipped
This means your trigger did not fire... so that means you no longer have a input type="image" name="Update" on your page?
roby258376
04-13-2009, 07:10 AM
Hi Ray,
Following the solution recipe, I first changed the existing image field from "text" to hidden.
I then added the new file field, as directed. The code I ended up with is:
<tr>
<th>picture:</th>
<td><img src="<?php echo $row_WAATKmembers['picture']; ?>" alt="img" width="80" />
<input type="hidden" class="WAATKTextField" name="picture" id="picture" value="<?php echo(str_replace('"', '"', $row_WAATKmembers['picture'])); ?>" size="32" />
<input type="file" name="pictureFile" id="pictureFile" /></td>
</tr>
</table>
<div class="WAATKButtonRow">
<input type="image" hspace="0" vspace="0" border="0" name="Update" id="Update" value="Update" alt="Update" src="WA_SecurityAssist/images/Pacifica/Elemental_update.gif" />
<input name="UserID" type="hidden" id="WAATKUpdateRecordID" value="<?php echo(rawurlencode($row_WAATKmembers['UserID'])); ?>" />
</div>
</form>
Ray Borduin
04-13-2009, 08:10 AM
Please submit a support ticket. I can't tell why it might not be working, so we may need to have a webassist support engineer debug this with you.
roby258376
04-13-2009, 08:14 AM
Will do, thanks for your help
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.