We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Get file upload include to work (show up) in new module (need work around)

Development and Programming

Aquarian Web Studio's avatar
Aquarian Web Studio
193 posts
16 years ago
Aquarian Web Studio's avatar Aquarian Web Studio
$r .= $DSP->table_qcell('tableCellOne', include('upload-insert.php')
                                        , '50%');

.. I’m trying to work with EE’s globals in building an admin table for this particular module, that adds records to a table. One of those records is a file that needs to be uploaded at this time. I found a file uploader that should work with a little tweaking but I cannot get it to show up, as I have not yet been able to get the file contents to render.

Placing the file within the $DSP parameter would look like this:

$r .= $DSP->table_qcell('tableCellOne', require_once 'class.FlashUploader.php'.IAF_display_js().$uploader = new FlashUploader('uploader', 'uploader', 
'upload.php').$uploader->display()
                                        , '50%');

This is only a flash uploader and it is entirely php based with a little bit of independent javascript. Is it possible to integrate such an element in an mcp? I don’t know flash very well and since this is php based I though I might be able to integrate it but I’m having no luck.

How would I work with the $DSP class to include a file (within the same module folder?)

I’ll be in some trouble if I can’t figure out how to get this to work. Thanks.

       
Aquarian Web Studio's avatar
Aquarian Web Studio
193 posts
16 years ago
Aquarian Web Studio's avatar Aquarian Web Studio

On a semi-related note, can you embed a module into another module?

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
16 years ago
Pascal Kriete's avatar Pascal Kriete

You certainly can embed any php file in your module. In this case, you’re mixing a bunch of stuff, so we’re going to untangle a bit first.

First up, require/include/etc. These functions make the variables, classes, and functions inside a file available for you to use in PHP, but they don’t actually pass back a string of text, or anything of use for that matter.

So what we want to do first is simply include the class, do it before you start building the table (this will make sense in a little bit):

require_once 'class.FlashUploader.php';

That file contains a function (IAF_display_js) and a class (FlashUploader), both of which we can now use. We’ll create the object for later use:

$upload_obj = new FlashUploader('uploader', 'uploader', 'path/to/upload.php');

A note here - simply linking to upload.php will not work, the url won’t resolve properly. You’ll need move the upload code to a function inside your mcp file and then link to that using the existing constants:

$upload_obj = new FlashUploader('uploader', 'uploader', BASE.AMP.'C=modules'.AMP.'M=modulename'.AMP.'P=uploadmethod');

Now we can add to the output, by simply appending the returned values:

// Before beginning the table so that our js isn't in a table (ugly :wink: ):
$r .= IAF_display_js();

// And later on the row:
$uploader = $upload_obj->display()
$r .= $DSP->table_qcell('tableCellOne', $uploader, '50%');

The uploader file needs some tweaking for this to output correctly. Currently both IAF_display_js and display() echo their string, they need to return it instead.

That should get you started. I’ve never used the uploader in question so I’m just going by what I can see, no guarantees. You will definitely need to do some tweaking to the actual upload handling as outlined above. You may also want to consider using the existing EE upload library (core/core.upload.php) instead of the provided upload handling code (which is a bit sparse).

One last note - flash has problems with sending cookies on windows (except for Internet Explorer). So your uploads may not work for everyone if you’re using cookie sessions.

Good luck 😊 .

       
Aquarian Web Studio's avatar
Aquarian Web Studio
193 posts
16 years ago
Aquarian Web Studio's avatar Aquarian Web Studio

Wow, SO glad you could provide this! Thank you.

How would I use core.upload.php?? Do you have any good links? I’m sure with the right documentation I could migrate what I need.

Again. ThaNKS!!

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
16 years ago
Pascal Kriete's avatar Pascal Kriete

Unfortunately we don’t have any formal documentation for that particular library. Looking through the upload_form function in mcp.wiki might help though 😊 .

       
Aquarian Web Studio's avatar
Aquarian Web Studio
193 posts
16 years ago
Aquarian Web Studio's avatar Aquarian Web Studio
@extract($_GET);
    
    $filename    = $_FILES['Filedata']['name'];
    $temp_name    = $_FILES['Filedata']['tmp_name'];
    $error        = $_FILES['Filedata']['error'];
    $size        = $_FILES['Filedata']['size'];
    
    /* NOTE: Some server setups might need you to use an absolute path to your "dropbox" folder
    (as opposed to the relative one I've used below).  Check your server configuration to get
    the absolute path to your web directory*/
    if(!$error)
        copy($temp_name, '../dropbox/'.$filename);

The above is the upload.php bit. Am I going to be able to use these globals?

       
Aquarian Web Studio's avatar
Aquarian Web Studio
193 posts
16 years ago
Aquarian Web Studio's avatar Aquarian Web Studio

I have this ready to test - your suggestions regarding return vs echo were right on!

Its not displaying the SWF file however.. its looking for it in the same directory:



<pre><code><embed src=”uploader.swf” FlashVars=”allowResize=’+e+..</code></pre>

I’ve checked for JS errors, and all of my other tools just say “movie not loaded”..

Can you think of any other way to check into this? Thank you so much.

EDIT:: I keep trying to get around just calling the .swf file in plain code like assigning it to a variable and pulling it in that way but predictably, I can’t seem to get around just having to get the file from somewhere. in using “BASE” I get the session Id on there before I append the file path and the link breaks. Any ideaS?

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
16 years ago
Pascal Kriete's avatar Pascal Kriete

First re:globals, yes you can. But as I mentioned it’s not a great piece of code. Extracting $_GET is about as evil as it gets.

The directory of the uploader is relative to the path in the browser when the page is loaded. In the case of the control panel, that’s system/index.php - so you’re not looking in the same directory. I would suggest moving the swf file to your public images folder and then linking to that.

       
Aquarian Web Studio's avatar
Aquarian Web Studio
193 posts
16 years ago
Aquarian Web Studio's avatar Aquarian Web Studio

oh-k!

I got it to show up. Next I will look back into turning the upload code into EE’s - the main thing at this point was getting it to show up. It finally has..

You’re great!

thanks, .ccb.

       
Aquarian Web Studio's avatar
Aquarian Web Studio
193 posts
16 years ago
Aquarian Web Studio's avatar Aquarian Web Studio

I’ve begun the process of moving this code into much more expression-engine friendly code.

But without documentation I’m running into trouble (again).

For example, now that the movie is showing up, its uploading test files, or so it says it is, but they’re not showing up in the destination folder. Having pretty much assumed that paths are more than just a little complicated when working with MCP, I placed the specified error recording files in a couple of different places and moved to the error troubleshooting code:

/* NOTE: This file will print all passed variables (sent using pass_var) and all uploaded file
    information to a file called output.txt (you can change this below) in order to debug the utility.
    If nothing is printed to output.txt it is either a permission problem (make the folder this file
    is in writeable) or your path to the upload.php file (the 3rd paramater of the $uploader->create()
    function) is wrong. Make sure you use a full web path if you are having problems (such as
    http://www.inaflashuploader.com/uploader/upload.php)*/
    
    @extract($_GET);
    
    ob_start();
    
    $filename        = $_FILES['Filedata']['name'];
    $temp_name    = $_FILES['Filedata']['tmp_name'];
    $error            = $_FILES['Filedata']['error'];
    $size                = $_FILES['Filedata']['size'];
    
    print_r($_GET);
    echo "\n\n";
    print_r($_FILES);
    echo "\n\n";
    
    /* NOTE: Some server setups might need you to use an absolute path to your "dropbox" folder
    (as opposed to the relative one I've used below).  Check your server configuration to get
    the absolute path to your web directory*/
    if(!$error)
        copy($temp_name, '../dropbox/'.$filename);
        
    $output = ob_get_contents(); ob_end_clean();
    
    //write all output and variables to a file
    $f = fopen('output.txt', 'w+');
    fwrite($f, $output);
    fclose($f);

But since this is entirely print oriented nothing shows up, and it doesn’t find the file to write errors to. So now I’m thinking - lets just make this entirely an EE file upload and scrap the code that this came with.

Using examples from mod.wiki (Upload_form()) I’m noticing that there’s no obvious place to specify which upload prefs to use. Perhaps this is because they are too far into the prefs of the wiki system and are preset before this particular function is called.

Then, in trying to migrate different variables away from @extract($_GET), I’m realizing that this file uploader is essentially creating a form within a form, or the flash is doing something that I can’t change. Rather I have no idea how its assigning variables or passing them. I’d like to be able to use it, but then again, its starting to seem like a file type input would be more straight-forward (even though its not supported by the $DSP class which is why I went for a flash one anyway.)

If this flash thing is using $_GET variables, then is it submitting through php and killing the other form I’m trying to embed the uploader into? Its essentially an array of fields designed to keep track of information, one thing being the filename, and upload the file and grab the filename at the same time. Trying to migrate all of the above to EE uploaders feels like jumping into the ocean. I don’t know what needs to get set up where, because the new Uploader() brings everything together and I can’t get a good grasp on what its doing with the variables. Like, how can you have $_gET variables when you stay on the same page?

I’m starting to feel like what I’m trying to do is impossible, but surely this is not the case.

Thank you for all your help so far.

EDIT:: As I begin to understand EE’s interface a little more I’m thinking that even though this thing claims to be uploading files, its not moving onto the processing stage. Would I need to use ajax to get this to function?

       
Aquarian Web Studio's avatar
Aquarian Web Studio
193 posts
16 years ago
Aquarian Web Studio's avatar Aquarian Web Studio

OK - so I’ve abandoned the flash file upload.

I’m using core.upload.php

.. and it works.

Thanks for your help. .ccb.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.