Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

$_FILES, upload.php & problems


w2e

Recommended Posts

Hi,

I am trying to upload an image from a local directory to the web server.

 

For the user to choose the image I have:

<tr class="infoBoxContents">

<td class="main"><?php echo ENTRY_LOGO; ?></td>

<td class="main"><?php echo tep_draw_file_field('suppliers_logo') . ' ' ?></td>

</tr>

 

and to save the image:

$logo= new upload(stripslashes($suppliers_logo),DIR_FS_CATALOG_IMAGES);

 

 

The 'suppliers_logo' string is set ok (shown as the full path inc. drive letter) but in upload.php parse(), it all sees to fall apart:

 

function parse() {

global $messageStack;

 

echo 'file '.$this->file.'<br>';

 

if (isset($_FILES[$this->file])) {

//if (isset($this->file)) {

$file = array('name' => $_FILES[$this->file]['name'],

'type' => $_FILES[$this->file]['type'],

'size' => $_FILES[$this->file]['size'],

'tmp_name' => $_FILES[$this->file]['tmp_name']);

 

....whilst I get on screen:

'file C:\want2eat\htdocs\osc\catalog\images\banners\oscommerce.gif',

isset($_FILES[$this->file])) is false, and control drops down to:

 

...isset($GLOBALS[$this->file . '_name']) ? $GLOBALS[$this->file . '_name'] : '')...

 

and so all array variables are set to ''.

 

Its probably a very simple issue related to the file path string - but what exactly ?

 

Thanks in advance,

Martin

Link to comment
Share on other sites

and to save the image:
$logo= new upload(stripslashes($suppliers_logo),DIR_FS_CATALOG_IMAGES);

 

try changing to

 

and to save the image:
$logo= new upload(stripslashes('suppliers_logo'),DIR_FS_CATALOG_IMAGES);

notice the $ from the suppliers_logo is removed.....I am not sure how well the stripslashes works there, nor if the setting of the destination folder will work well either.....(I have not tried it)..

 

cheers,

Peter M.

Peter McGrath

-----------------------------

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Link to comment
Share on other sites

Peter,

Thanks for this - but that actually makes it worse since it then delivers 'suppliers_logo' as the file name.

Unfortunately I fear its something more to do with upload.php than my call to it - since the filename I pass is picked up (as the test echo I use in upload.php shows the correct fully qualified path). But after then, doing isset($_FILES[$this->file]) on this path returns a negative, so the appropriate array variables cannot be set & so it all falls apart....part of the issue is me not knowing what $_FILES is expecting & doing.

 

Any other ideas ?

Thanks

Martin

Link to comment
Share on other sites

I understand that you can give a file a name, but you are doing it wrong from my understanding of the upload class. I have yet to be able to get the POSTed info and send it as a variable to the class, generally you would get the POSTed info via the POSTed varialble name, and not rename this info to something different. If you are looking to rename the image, then this can be done, but use the $image->set_name function....

 

here is some code I use, which does the renameing etc....

 

 

        
       $store_logo_image = new upload('store_image');
       $store_logo_image->set_destination($newname);
       $store_logo_image->set_extensions($allowed_files_types);        
       $parsed = $store_logo_image->parse();
       $ext = (substr($store_logo_image->filename, -4));
       $store_logo_image->set_filename('logo' . $ext);
       $saved = $store_logo_image->save();

       if ($parsed && $saved){
         $store_logo_image_name = $store_logo_image->filename;
       }else{
         $store_logo_image_name = ''; 
       }

 

which might clear it up a bit for you.....

 

cheers,

Peter M.

Peter McGrath

-----------------------------

See my Profile (click here) for more information and to contact me for professional osCommerce support that includes SEO development, custom development and security implementation

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...