RegisterRegister    SearchSearch   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

File sharing script

File mirror script
Call existing PHP variables

 
Post new topic   Reply to topic    SibSoft Ltd Forum Index -> XUpload
View previous topic :: View next topic  
Author Message
Nicola



Joined: 06 Mar 2012
Posts: 3

PostPosted: Mar 06, 2012 9:24 pm    Post subject: Call existing PHP variables Reply with quote

Hi
I want to integrate xupload pro into a existing PHP code

PHP code checks this:

-Maximum file size allowed
-Store uploaded files in dynamic folders
-Assign a unique id / name to each uploaded file
-Check the file extension

But there's no official function that is used to monitor the progress of file upload

Can you help me?

here is the php code:

Code:

   private function uploadConfigurableFile($fieldOptions, $file)
   {
      if (!is_array($fieldOptions) || !is_array($file) || empty($file['name'])) {
         return false;
      }

      $extension = GetFileExtension($file['name']);
      $allowedExtensions = array_map('trim', explode(',', $fieldOptions['fieldfiletype']));
      $allowedExtensions = array_map('isc_strtolower', $allowedExtensions);
      if ($fieldOptions['fieldfiletype'] && !in_array(isc_strtolower($extension), $allowedExtensions)) {
         throw new ISC_QUOTE_EXCEPTION(sprintf(GetLang('InvalidFileType'), isc_html_escape($fieldOptions['fieldfiletype'])));
      }

      // Check that the maximum size is not exceeded
      if ($fieldOptions['fieldfilesize'] > 0 && $file['size'] > $fieldOptions['fieldfilesize']*1024) {
         throw new ISC_QUOTE_EXCEPTION(sprintf(GetLang('InvalidFileSize'), $fieldOptions['fieldfilesize']));
      }

      // Store the uploaded files in our configured products directory
      $uploadDirectory = ISC_BASE_PATH.'/'.GetConfig('ImageDirectory').'/configured_products_tmp/';
      if (empty($file['existingPath'])) {
         /**
          * @todo Implement temporary sharing/storage location with automatic pruning.
          */
         $fileName = $fieldOptions['productfieldid'].'_'.md5(uniqid()).'.'.$extension;
         if (!move_uploaded_file($file['tmp_name'], $uploadDirectory.$fileName)) {
            throw new ISC_QUOTE_EXCEPTION(getLang('CanNotUploadFile'));
         }
      }
      else {
         $fileName = basename($file['existingPath']);
      }

      // If we've just uploaded an image, we need to perform a bit of additional validation
      // to ensure it's not someone uploading bogus images.
      $imageExtensions = array(
         'gif',
         'png',
         'jpg',
         'jpeg',
         'jpe',
         'tiff',
         'bmp'
      );
      if (in_array($extension, $imageExtensions)) {
         // Check a list of known MIME types to establish the type of image we're uploading
         switch(isc_strtolower($file['type'])) {
            case 'image/gif':
               $imageType = IMAGETYPE_GIF;
               break;
            case 'image/jpg':
            case 'image/x-jpeg':
            case 'image/x-jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
            case 'image/jpg':
               $imageType = IMAGETYPE_JPEG;
               break;
            case 'image/png':
            case 'image/x-png':
               $imageType = IMAGETYPE_PNG;
               break;
            case 'image/bmp':
               $imageType = IMAGETYPE_BMP;
               break;
            case 'image/tiff':
               $imageType = IMAGETYPE_TIFF_II;
               break;
            default:
               $imageType = 0;
         }

         $imageDimensions = getimagesize($uploadDirectory.$fileName);
         if (!is_array($imageDimensions) || $imageDimensions[2] != $imageType) {
            @unlink($uploadDirectory.$fileName);
            throw new ISC_QUOTE_EXCEPTION(GetLang('InvalidImageFile'));
            return false;
         }
      }

      return $fileName;
   }
   public function applyConfiguration($configuration)
   {
      $configurableFields = $this->getConfigurableOptions();

      // Get the current configuration
      $existingConfiguration = $this->configuration;

      $newConfiguration = array();

      foreach ($configurableFields as $fieldId => $field) {
         if ($field['fieldrequired'] && empty($configuration[$fieldId]) &&
            empty($existingConfiguration[$fieldId])) {
               throw new ISC_QUOTE_EXCEPTION(getLang('EnterRequiredField'));
         }

         if ($field['fieldtype'] == 'file') {
            // Field was empty, use existing value
            if (empty($configuration[$fieldId]['name']) && !empty($existingConfiguration[$fieldId])) {
               $newConfiguration[$fieldId] = $existingConfiguration[$fieldId];
               continue;
            }
            else if(empty($configuration[$fieldId]['name'])) {
               continue;
            }

            // If we can't save the uploaded file, throw back an error
            $uploadedFile = $this->uploadConfigurableFile($field, $configuration[$fieldId]);
            if ($uploadedFile === false) {
               throw new ISC_QUOTE_EXCEPTION(getLang('CanNotUploadFile'));
            }

            // If there was an existing file, delete it
            if (isset($existingConfiguration[$fieldId]['value']) &&
               $existingConfiguration[$fieldId]['value'] != $uploadedFile) {
                  $this->deleteConfigurableFile($fieldId, true);
            }

            $newConfiguration[$fieldId] = array(
               'type'            => $field['fieldtype'],
               'name'            => $field['fieldname'],
               'fileType'         => $configuration[$fieldId]['type'],
               'fileOriginalName'   => $configuration[$fieldId]['name'],
               'value'            => $uploadedFile,
            );
            continue;
         }
         elseif ($field['fieldtype'] == 'select') {
            $newConfiguration[$fieldId] = array(
               'type'            => $field['fieldtype'],
               'name'            => $field['fieldname'],
               'selectOptions'      => $field['fieldselectoptions'],
               'value'            => $configuration[$fieldId],
            );
            continue;
         }

         if (!isset($configuration[$fieldId])) {
            continue;
         }

         $value = $configuration[$fieldId];
         $newConfiguration[$fieldId] = array(
            'type'   => $field['fieldtype'],
            'name'   => $field['fieldname'],
            'value'   => $configuration[$fieldId],
         );
      }

      // Store the finalized configuration for this product
      $this->setConfiguration($newConfiguration);
      return $this;
   }
Back to top
View user's profile Send private message
Nicola



Joined: 06 Mar 2012
Posts: 3

PostPosted: Mar 07, 2012 8:18 am    Post subject: Reply with quote

I searched in Google and found this:

In PHP file:
Code:

exec('./perl_script.pl foo=bar');


Or add a space between the command and the variable. If the variable contains spaces, you also need to use the escapeshellarg function:

Code:

exec('./perl_script.pl'.' '.EscapeShellArg($variable));


In Perl file (use the -s switch):
Code:

#!/usr/bin/perl -s
use vars ($foo);

if $foo do_something;


Is It the way for the solution?

Another suggestion found is:

Code:

#!/usr/bin/perl

print $ARGV[0];
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 22 Mar 2006
Posts: 1488

PostPosted: Mar 07, 2012 10:53 am    Post subject: Reply with quote

I can't imagine why you would need to call perl script from php script.

I think you're getting whole upload conception the wrong way.
XUpload uploading file by itself, then after upload it's sending POST request to your php script and sending information about uploaded files (location, size, etc).
Back to top
View user's profile Send private message Send e-mail
Nicola



Joined: 06 Mar 2012
Posts: 3

PostPosted: Mar 07, 2012 11:02 am    Post subject: Reply with quote

Hi admin
Thank you for the response

I'm very confuse: the various informations are sending by post.cgi code?

Then the post.cgi output must be imported in php variables?

Is it possible to change the function "private function uploadConfigurableFile" in the php file with a function that take the post.cgi data?

Or is it possible to send the parameters from php code to XUploadConfig.pm?
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 22 Mar 2006
Posts: 1488

PostPosted: Mar 07, 2012 12:08 pm    Post subject: Reply with quote

post.cgi is just the sample script which print all data posted by xupload to your script.
You should put your php script url in the url_post parameter in config file, so script will redirect user to your script after upload.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    SibSoft Ltd Forum Index -> XUpload All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright © 2003-2013 Sibsoft Ltd