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

Notification

Icon
Error

Options
Go to last post Go to first unread
TempPeck  
#1 Posted : Monday, September 9, 2013 11:57:13 PM(UTC)
TempPeck

Rank: Newbie

Groups: Member
Joined: 9/9/2013(UTC)
Posts: 5

Hi All,

I want to upload a number of pictures, re-name them and put the original and new name into a mySQL database using the ActiveX/Java Uploader.

Is there a demo or example that I could follow?

Thanks,
Andrew  
#2 Posted : Tuesday, September 10, 2013 12:43:09 AM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 870

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
Hello,

Well, it is not a big problem. In our standard demo application we save everything to XML file, just replace this code to the MySQL-related one. There is no any uploader-related code to deal with the database, but if you need to see some example, check out this post (not exactly what you are looking for, but a good start point):

http://forums.aurigma.co...t-to-mySQL-database.aspx
TempPeck  
#3 Posted : Tuesday, September 10, 2013 8:50:58 AM(UTC)
TempPeck

Rank: Newbie

Groups: Member
Joined: 9/9/2013(UTC)
Posts: 5

What am I suppose to have in the index file for this XML example?

Code:
require_once "ImageUploaderPHP/UploadHandler.class.php";

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

function saveAllUploadedFiles($uploadedFiles) {
    $galleryPath = "Gallery/";
    $absGalleryPath = realpath($galleryPath);
    $absThumbnailsPath = realpath($galleryPath . DIRECTORY_SEPARATOR . "Thumbnails/");
    
    //Create or load XML file which will keep information about files (image dimensions, description, etc).
    $descriptions = new DOMDocument('1.0');
    if (file_exists($absGalleryPath . DIRECTORY_SEPARATOR . "Descriptions.xml"))
        $descriptions->load($absGalleryPath . DIRECTORY_SEPARATOR . "Descriptions.xml");
    else
        $descriptions->appendChild($descriptions->createElement("files"));
    
    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()));
        $sourceFile->moveTo($absGalleryPath . DIRECTORY_SEPARATOR . $sourceFileName);
        
        //Save thumbnail.
        //It is the second file in ConvertedFiles collection as we set second converter mode to Thumbnail.
        $thumbnailFile = $convertedFiles[1];
        $thumbnailFileName = getSafeFileName($absThumbnailsPath, rawurlencode($uploadedFile->getSourceName()));
        $thumbnailFile->moveTo($absThumbnailsPath . DIRECTORY_SEPARATOR . $thumbnailFileName);
        
        //Save file info.
        $xmlFile = $descriptions->createElement("file");
        $xmlFile->setAttribute("name", $sourceFileName);
        $xmlFile->setAttribute("thumbName", $thumbnailFileName);
        $xmlFile->setAttribute("width", $uploadedFile->getSourceWidth());
        $xmlFile->setAttribute("height", $uploadedFile->getSourceHeight());
        $xmlFile->setAttribute("description", $uploadedFile->getDescription());
        $descriptions->documentElement->appendChild($xmlFile);
    }
    $descriptions->save($absGalleryPath . DIRECTORY_SEPARATOR . "Descriptions.xml");
}

function getSafeFileName($path, $fileName) {
    // ...
}
Andrew  
#4 Posted : Tuesday, September 10, 2013 8:17:03 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 870

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
The structure of our PHP online demo apps is the following:
  • index.php - the page where you insert the uploader control/applet. No XML file or database is involved on this stage.
  • upload.php - the code which processes the upload. In other words, the uploaders sends HTTP POST request to this script. In this code you parse files from the POST request, save them to the server hard drive, work with XML file or database, etc.
  • gallery.php - the example of the page which displays uploaded files. In our case it uses the XML file, but in a real-life application, it uses database.
If you want our demo app to work in the way, you described, you need to do the following:

Changes in upload.php

1. Modify the code which save files:

Code:
  // Save source file
  $sourceFile = $files[0];
  /* @var $sourceFile ConvertedFile */
  if ($sourceFile) {
    $sourceFileName = getSafeFileName($absGalleryPath, $originalFileName);
    $sourceFile->moveTo($absGalleryPath . $sourceFileName);
  }

Here you want to create your own file names instead of the original names (i.e. pass a custom file name to the moveTo method)

2. Instead of opening XML file:

Code:
  //Load XML file which will keep information about files (image dimensions, description, etc).
  //XML is used solely for brevity. In real-life application most likely you will use database instead.
  $descriptions = new DOMDocument('1.0', 'utf-8');
  $descriptions->load($absGalleryPath . 'files.xml');

You should open a connection to your MySQL instance.

3. Instead of creating an XML node and saving it to the XML file:

Code:
  //Save file info.
  $xmlFile = $descriptions->createElement('file');
  $xmlFile->setAttribute('name', $originalFileName);
  $xmlFile->setAttribute('source', $sourceFileName);
  $xmlFile->setAttribute('description', $uploadedFile->getDescription());
  $descriptions->documentElement->appendChild($xmlFile);
  $descriptions->save($absGalleryPath . 'files.xml');

You should insert data to your SQL server by executing SQL query like "INSERT INTO your_table (old_name_column, new_name_column, [...other columns]) VALUES ('$originalFileName', '$yourCustomFileName', [...other fields])".

Don't forget to close the SQL connection!

Changes in gallery.php

Generally speaking, you need to rewrite this page from a scratch to use your database instead of a PHP file. However probably you already have some code which displays files from your database.

Hope this helps.

Edited by user Tuesday, September 10, 2013 8:21:31 PM(UTC)  | Reason: Not specified

TempPeck  
#5 Posted : Wednesday, September 11, 2013 1:08:24 AM(UTC)
TempPeck

Rank: Newbie

Groups: Member
Joined: 9/9/2013(UTC)
Posts: 5

I'm getting a server side error. I stripped out all the XML code from your example and left everything else the same.

My index file
Code:
    <?php 
       require_once "ImageUploaderPHP/Uploader.class.php";

        // create Uploader object and specify its ID and size
        $uploader = new Uploader("Uploader1");
        $uploader->setWidth("650px");
        $uploader->setHeight("480px");
        
      // specify a license key
        $uploader->setLicenseKey("XXX-MY LICENSE KEY-XXX");
        // configure upload settings
        $uploader->getUploadSettings()->setActionUrl("upload_activex.php");
        $uploader->getUploadSettings()->setRedirectUrl("catalog.php");

        //configure uploaded files
        $converters = &$uploader->getConverters();
        // one converter for uploading source file
        $converter = new Converter();
        $converter->setMode("*.*=SourceFile");
        $converters[] = $converter;
        
        // render Uploader
        $uploader->render();

  
    ?>


My upload file (upload_activex.php)
Code:


<?php


require_once "ImageUploaderPHP/UploadHandler.class.php";

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

function saveAllUploadedFiles($uploadedFiles) {
    $galleryPath = "Gallery/";
    $absGalleryPath = realpath($galleryPath);
    $absThumbnailsPath = realpath($galleryPath . DIRECTORY_SEPARATOR . "Thumbnails/");
    
 
    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()));
        $sourceFile->moveTo($absGalleryPath . DIRECTORY_SEPARATOR . $sourceFileName);
        
        //Save thumbnail.
        //It is the second file in ConvertedFiles collection as we set second converter mode to Thumbnail.
        $thumbnailFile = $convertedFiles[1];
        $thumbnailFileName = getSafeFileName($absThumbnailsPath, rawurlencode($uploadedFile->getSourceName()));
        $thumbnailFile->moveTo($absThumbnailsPath . DIRECTORY_SEPARATOR . $thumbnailFileName);
   }

}

function getSafeFileName($path, $fileName) {
    // ...
}

?>



Am I missing something?

The standard auto upload example works fine.
I've set the permissions on the Gallery & Thumbnail folder to 777
Andrew  
#6 Posted : Wednesday, September 11, 2013 10:29:44 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 870

Thanks: 2 times
Was thanked: 26 time(s) in 26 post(s)
Server error means that the upload.php fails. The server response with the PHP error message and stack trace is sent to the uploader and you can see it in Java console output or have it to display a page with it using the DebugScriptMode as described here:

https://www.aurigma.com/...shooting-basic-steps.htm

On the first glance, it may fail if you did commented out getSafeFileName function body, because the code expects that it returns something.

BTW, why you inserted the empty getSafeFileName declaration? I have just checked our standard demo and we never declare it in upload.php. You can find its declaration in /Includes/gallery_helper.php.
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.