File upload function.

(7 posts) (2 voices)

Tags:

  1. ajdjackson, Member

    Hi

    In a follow up to my topic earlier today see here it would great if we had a cut down version of the dbr.import command - dbr.upload(?).

    What I would like is the ability to upload a local file without mydbr attempting to process the file and then run a user procedure to handle the file processing. So basically all the functionality of dbr.import without the processing.

    The server directory for the upload could be an environmental variable or just mydbr/user.

    This would give users more flexibility to handle files with different terminators, separators etc

    Any thoughts on how I could do this at present?

    Cheers

    Jake

  2. myDBR Team, Key Master

    While myDBR could do file uploads (the new 4.4.0 does uploads to mydbr/user directory for customization), just having myDBR to do uploads and not process the files gives quite a little advantage of all options usually available on serves (SSH etc).

    What would be a use case for this? Why not just upload with SSH or similar?

    One can create an extension to do upload.
    --
    myDBR Team

  3. ajdjackson, Member

    Hi

    In my case I just wish to be able to perform all the import steps from 1 application. The advantage of using mydbr (or another web app) is that it can be carried out using any device without the need to have specialist programs.

    But I understand what you are saying.

    May be I should have asked for additional functionality to be added to dbr.import.options that would allow more flexibility in the processing of the csv file such as be able to specify line and field terminators, fields enclosed by etc.

    Cheers

    Jake

  4. ajdjackson, Member

    Hi

    I've been playing around with the upload functionality in Server Side Files.

    I've been able to upload my file that will be processed with a Load Data Local Infile command.

    However I seem to have come across an issue that I can't find a fix for. Perhaps you can help me.

    The file when uploaded gets set with the following permissions: IIS_ISUSRS special permissions

    When I manually change these to give the IIS_ISUSRS read permission my import batch file runs correctly.

    The batch file that is run is as follows:

    cd C:\Program Files\Windows Server\Bin\WebApps\Site\mydbr\user CACLS AllProperties.csv /E /G IIS_IUSRS:r mysql --user=username --password=password --database=hilmark < c:/devc_import2.sql

    The CACLS doesn't do anything yet it works if I run it from a command window.

    Is there any reason that the uploaded file is set with special permissions only and could you change the upload to give it read as well?

    Hope you follow this.

    Thanks

    Jake

  5. myDBR Team, Key Master

    Jake, could you check what are the permissions on the upload_tmp_dir directory?

    We can add an option to set the file permissions to file transfers.
    --
    myDBR Team

  6. ajdjackson, Member

    Hi

    Your reply has pointed me in the right direction. Thanks.

    I had not set a specific upload_tmp_dir directory in php.ini and therefore the system default is being used - c:/windows/temp.

    I then realised that Windows copies the uploaded file to the mydbr/user folder with the permissions of this system folder.

    Checking the permissions of c:/windows/temp I saw that the IIS_ISUSR user was only special permissions.

    Once I added read permission I was able to process the uploaded file. :)

    What would be great would be if you would extract the upload facility as an extension then normal users would be able upload their own files for processing.

    Cheers, thanks and HAGWE

    Jake

  7. ajdjackson, Member

    Hi

    I now have created the following report (?):

    DROP PROCEDURE IF EXISTS sp_DBR_Test_Import $$ CREATE PROCEDURE sp_DBR_Test_Import() BEGIN

    select 'dbr.html','<form action="user/upload.php" method="post" enctype="multipart/form-data"> Select image to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload AllProperties File" name="submit"> </form> ';

    END $$

    The php file is a rather basic uploader that I'll develop further.

    <?php $target_dir = "../user/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $FileType = pathinfo($target_file,PATHINFO_EXTENSION); $FileName = pathinfo($target_file,PATHINFO_BASENAME); // Check if file already exists /*if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; }*/ // Check file size if ($_FILES["fileToUpload"]["size"] > 500000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($FileName != "AllProperties.csv" ) { echo "Sorry, only AllProperties.csv is allowed."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else {

    if (copy($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } ?>

    This works fine in that I can select the file and it uploads as required.

    I'm now stuck at how to incorporate the above.

    I would like to call the SP that then processes the uploaded file.

    I've tried to call the SP that does the processing from the upload.php file but I can't get it to work.

    If I add the upload form section into the processing SP the SP doesn't wait until the file gets uploaded.

    Any pointers on how I can use the above?

    Cheers

    Jake


Reply

You must log in to post.