Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
WFUK  
#1 Posted : Wednesday, July 27, 2011 12:03:43 AM(UTC)
WFUK

Rank: Newbie

Groups: Member
Joined: 2/10/2011(UTC)
Posts: 9

Hi all,

I am hoping the smart people on these forums could help me out with an issue I am having whilst intergrating Aurigma image uploader into my web site.

This is the current set up I have (PHP):

1) Image uploader is displayed on page for the user to upload images (the web site is for van dealers advertising their vehicles for sale)

2) The process page (i.e. the page which uploads the images and is set in $uploader->getUploadSettings()->setActionUrl) creates a temp folder (which is the ID number of the van so they are unique), sets the folders permission to writable so the images can be uploaded, and then that is the folder declared for $uploadHandler->saveFiles

3) We then redirect to another page which copies the images from the temp folder, renames and saves the images to the proper folder, and then we delete the temp folder.

May be a long-winded way, but I do this so we can rename the image names for SEO reasons (e.g. ford-transit-van-for-sale-london-123.jpg)

This method works in I.E. but doesn't work in Firefox. I found this a bit strange, and then came to the conclusion that the Java Applet which is calling on the process page is not allowing that page, for whatever reason, to set up the temp folder and set its new writtable permission.

I have zero knoweldge of Java and how it works, so I am a little lost as to what to do to resolve this issue! I did have this issue a few months back, so I put a sleep(8) into the PHP before setting the permissions, which works for a limited time, but for some reason it no longer works, and that was abit of a hacky fix anyway.

Hopefully there will be someone with Java know-how who will be able to give some pointers on what I can do?

Many thanks!

Edited by user Wednesday, July 27, 2011 12:05:04 AM(UTC)  | Reason: Not specified

p.shirykalova  
#2 Posted : Wednesday, July 27, 2011 1:16:04 AM(UTC)
p.shirykalova

Rank: Advanced Member

Groups: Member
Joined: 7/13/2011(UTC)
Posts: 286

Thanks: 6 times
Was thanked: 31 time(s) in 31 post(s)
Hello,

Could you please use Java Console and send us the results?

1. Run your site in Firefox, go to your Image Uploader page,

2. In the tray you will see Java icon, right-click on it and select Open Console command,

3. Try to upload something,

4. Check if there are some error messages dumped in Java Console

5. Send us the results

Learn more about using Java Console.

Also please provide us with the link to your site (login/password) where you experience this problem. You can add new support case and specify this information there.

I noticed that you have an extra step using temp directory to rename files. I see two possible ways how you can rename them on server side:

1. Using new instance of UploadHandler class. In this case you need to use FileUploadedCallback or AllFilesUploadedCallback events. Here is the code snippet illustrating it:

Code:
<?php

$handler = new UploadHandler();
$handler->setAllFilesUploadedCallback("saveAllUploadedFiles");
$handler->processRequest();

function saveAllUploadedFiles($uploadedFiles) {
    $galleryPath = "Gallery/";
    $absGalleryPath = realpath($galleryPath);
        
      
    foreach ($uploadedFiles as $uploadedFile)
    {
        $convertedFiles = $uploadedFile->getConvertedFiles();
        //Save original file.
        //It is the first file in ConvertedFiles collection as we set first converter mode to SourceFile.
        $sourceFile = $convertedFiles[0];
        getSafeFileName($absGalleryPath, rawurlencode($uploadedFile->getSourceName()));
		$sourceFileName = "AnyNameYouNeedToSet".".jpg";
        $sourceFile->moveTo($absGalleryPath . DIRECTORY_SEPARATOR . $sourceFileName);
 
}

?>

2. Parsing POST request on the server side:

Code:

<?php
require_once "ImageUploaderPHP/PostFields.class.php";

// Check if it is POST request;
// we should not try to save files in HEAD requests.
if ($_SERVER['REQUEST_METHOD'] != 'POST') 
  exit();

$galleryPath = "Gallery";
$absGalleryPath = realpath($galleryPath);


//Get number of files in the current package.
$fileCount = $_POST[PostFields::packageFileCount];

//Iterate through uploaded data and save the original file, thumbnail, and description.
for ($i = 0; $i < $fileCount; $i++) {
    
    //save source file
    sourceFileName = "AnyNameYouNeedToSet".".jpg";
    if (isset($_FILES[sprintf(PostFields::file, 0, $i)])) {
        move_uploaded_file($_FILES[sprintf(PostFields::file, 0, $i)]["tmp_name"], 
            $absGalleryPath . DIRECTORY_SEPARATOR . $sourceFileName);
    }
?>

Please read more about these ways I listed in the Saving Uploaded Files in PHP topic.

If you have any additional questions feel free to ask.

Edited by user Wednesday, July 27, 2011 1:52:22 AM(UTC)  | Reason: Not specified

Best regards,

Pauline Shirykalova

Aurigma Technical Support

WFUK  
#3 Posted : Friday, July 29, 2011 5:48:40 AM(UTC)
WFUK

Rank: Newbie

Groups: Member
Joined: 2/10/2011(UTC)
Posts: 9

Many thanks for your reply!

I have tried using the function callback method so I can rename the images. I have copied your code but it doesn't seem to work:

Code:

require_once "ImageUploaderPHP/UploadHandler.class.php";

function saveAllUploadedFiles($uploadedFiles) {     
$galleryPath = "test/";     
$absGalleryPath = realpath($galleryPath);   
				                    
$i=0;
foreach ($uploadedFiles as $uploadedFile) { 
$i++;        
$convertedFiles = $uploadedFile->getConvertedFiles();  
//Save original file.         
//It is the first file in ConvertedFiles collection as we set first converter mode to SourceFile.         
$sourceFile = $convertedFiles[0];         
getSafeFileName($absGalleryPath, rawurlencode($uploadedFile->getSourceName()));      
$sourceFileName = "AnyNameYouNeedToSet".$i."".".jpg";         
$sourceFile->moveTo($absGalleryPath . DIRECTORY_SEPARATOR . $sourceFileName);  
  } 
}
			
$handler = new UploadHandler(); 
$handler->setAllFilesUploadedCallback("saveAllUploadedFiles"); 
$handler->processRequest();   

The test folder is writtable. I have tried to debug by making the script e-mail me at certain points, and the script seems to run okay until the line:

Code:
getSafeFileName($absGalleryPath, rawurlencode($uploadedFile->getSourceName()));

But after this the script seems to cease working?

Thanks

Edited by moderator Sunday, July 31, 2011 9:53:01 PM(UTC)  | Reason: Not specified

p.shirykalova  
#4 Posted : Monday, August 1, 2011 12:58:10 AM(UTC)
p.shirykalova

Rank: Advanced Member

Groups: Member
Joined: 7/13/2011(UTC)
Posts: 286

Thanks: 6 times
Was thanked: 31 time(s) in 31 post(s)
Hello,

getSafeFileName() function is used for preventing conflicts between files with the same names.

You get an error because you called this function without implementation.

The solution is very simple:

  1. You can remove this line from your code if you don't need this function.

  2. If you need to generate new file name if the conflict occurs, implement this function like in example (or use your own code)

    Code:
    
    /**
     * Check if file with the same name exists then add index
     * to the file name to avoid to overwrite other files.
     * @param $path path to save file
     * @param $fileName file name
     * @return string new file name
     */
    function getSafeFileName($path, $fileName, $overwrite = FALSE) {
    
      // Replace special characters in the file name
      $fileName = preg_replace('/[^a-z0-9_\-\.()\[\]{}]/i', '_', $fileName);
    
      if (!$overwrite && file_exists($path . $fileName)) {
        $file_parts = pathinfo($fileName);
        //get fileName without extension
        $newFileName = $file_parts['filename'];
        //get extension
        $ext = $file_parts['extension'];
        if ($ext != '') {
          $ext = '.' . $ext;
        }
        $i = 0;
        while (file_exists($path . $newFileName . '_' . $i . $ext)) {
          $i++;
        }
        return $newFileName . '_' . $i . $ext;
      } else {
        return $fileName;
      }
    
    }
    

Best regards,

Pauline Shirykalova

Aurigma Technical Support

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.