Forum Moderators: coopster

Message Too Old, No Replies

Image Upload not working

a new osCommerce tool that should work but...

         

lorax

3:57 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I've built a new tool that's a copy of the banner admin tool in osCommerce so that I can include product and category specials on the home page. I've added the module to the Tools section and everything has been going swimmingly with the exception of the image upload. The target image directory has 777 permissions. And the file paths all seem to be correct. The other image uploading tools all work fine thus the class and functions are working. So I need a bit of help as I troubleshoot my way through this.

The input on the form is as follows:

<tr>
<td class="main" valign="top"><?php echo TEXT_ADS_IMAGE;?></td>
<td class="main"><?php echo tep_draw_file_field('ads_image_file') . ' &nbsp; Current Image: <b>'.(isset($bInfo->ads_image)? $bInfo->ads_image : '').'</b>';?></td>
</tr>

Which yields this in HTML:

<tr>
<td class="main" valign="top">Image:</td>
<td class="main"><input type="file" name="ads_image_file"> &nbsp; Current Image: <b></b></td>
</tr>

Now my understanding of the image upload process is that PHP will take the file and upload it to a temp directory and if that succeeds, the PHP osCommerce script will copy that temp file to a location specified in the script. Like I said, it class and functions for the upload work for the other uploading tools.

So here's a two part question.

First, when I try to view the value of the field $ads_image_file I get the temp file name rather than the actual filename. Why?

Second, while the script runs without errors, the file never makes it to it's destination. The particular section I'm testing updates an existing db record. Text edits are completed without error. Here's the pertinent code for that section:


if (isset($HTTP_POST_VARS['ads_id'])) $ads_id = tep_db_prepare_input($HTTP_POST_VARS['ads_id']);
$ads_title = tep_db_prepare_input($HTTP_POST_VARS['ads_title']);
$ads_copy = tep_db_prepare_input($HTTP_POST_VARS['ads_copy']);
$ads_product_url = tep_db_prepare_input($HTTP_POST_VARS['ads_product_url']);
$ads_image = tep_db_prepare_input($ads_image_file);
$db_image_location = '';

$ad_error = false;
if (empty($ads_title)) {
$messageStack->add(ERROR_AD_TITLE_REQUIRED, 'error');
$ad_error = true;
}

if (empty($ads_copy)) {
if (empty($ads_image)) {
$ads_image = new upload('ads_image');
$ads_image->set_destination(DIR_FS_CATALOG_ADS . $ads_image);
if ( ($ads_image->parse() == false) ¦¦ ($ads_image->save() == false) ) {
$ad_error = true;
}
}
}


The bolded sections are the ones I've been investigating. I'm getting close to being stumped. You're help and/or insight would be most appreciated.

lorax

4:17 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



DOH!
Nevermind - I found the error - or rather I remembered that when files are uploaded they are not included in the HTTP_POST_VARS array but rather in the $_FILES array.

coopster

10:58 pm on Oct 20, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



hehe. Been awhile, eh lorax? You were probably referring to $HTTP_POST_FILES rather than $HTTP_POST_VARS...


The global $_FILES [php.net] exists as of PHP 4.1.0 (Use $HTTP_POST_FILES instead if using an earlier version). These arrays will contain all the uploaded file information.

Either way, glad you got it sorted :)