Re: File Uploading - A possible attempt

Thanks for answers.

Now on your site the script works perfectly, the indicator of loading is displayed correctly.

But on localhost on former it is created only four tempfiles and there is no creation of an oroginal file. I have certainly changed function (fileAction), but, apparently, does not reach its call for some reason.

Besides, you have made what adjustments that the indicator of loading was correctly displayed and in IE7?

Thanks.

Sorry for my bad English

Re: File Uploading - A possible attempt

Honestly, I haven't done anything to make IE7 work.  The only thing that I did was to fix my file viewer tool so that it could display special characters.  I don't know why it is now working for you.  Again, I am guessing it is an issue with timing and the internet lag.

As for your local hosting issue, you should find that the 4 files are created in the process, but after the upload is completed, they should automatically be deleted by the following php code found in upload_xajax_inc.php line 110.

                // CLEANUP FILES.
                foreach($exts as $ext) {
                    if(file_exists($uploadDir.$sid.$ext)) {
                        unlink($uploadDir.$sid.$ext);
                    }
                }

Here is a more detailed explanation:
1) During the upload there will be 2 files (???_flength and ???_postdata).
2) When upload has completed, 2 more files are created (???_qstring and ???_signal).
3) Additionally, on completion, the cgi script should generate a file with a temp name for each file that was selected for upload.  These are the actual files that were selected for upload except that each has a temp name assigned.  For example, if you uploaded 3 files, you should find 3 new files in your temp folder with names that are randomly generated like this for example

8umW8ufifQ
NuegZoOQ1o
tGoZxfdVjf

4) After the these files are created, the fileAction function is called and your files are manipulated in whatever way you have coded.
5) After the fileAction completes, the CLEANUP FILES code executes and deletes all of the temp files except for the completed uploads.  If you want to get rid of the completed uploads, then you should accomplish that in your fileAction by unlinking the $fileArr['tmp_name'] or by moving the temp file in some other way (such as the rename command as my demo provides).

The above process explains how things should work in a start-to-finish upload.  If you cancel the upload, or if there is some other error (such as max file size issue) then that is another story.

Regarding your problem specifically, I am wondering if perhaps you don't have the appropriate rights set on the temp folder.  If you set cgiDebug =1 in your config file, do you get any errors like "PHP is not able to read the temp dir!!"??

103 (edited by 6epcepk 2007-03-26 9:53:57 PM)

Re: File Uploading - A possible attempt

I have found mistake. I modified a script for work with xajax 0.5, and probably something has made not correctly. How you consider, whether expediently to use latest the version xajax?
Thanks for answers!

Sorry for my bad English

Re: File Uploading - A possible attempt

Hi All

Why not create a sub-group and deal with upload as a xajax plugin project.

Just some random thoughts!!

Why not NOT create a random filename and instead name the upload the same name as the filename.  After all they are being sent to tmp storage.  Often the file uploaded name is inserted into a database with path info etc, etc.  When dealing with dozens or hundreds of uploaded files it's helpful to quitely id the uploaded file by it's name.  If your code is designed to upload one file by one guy then aok but if you want to have dozens of guys upload dozens of files at or about the same time maybe the approach should be to design upload as a php class.

I'm not sure why the last 10 or so update are in this thread.   Are we trying to re-invent the wheel? It's seems way off the the orginial essences, except for the word upload or perhaps it started when 0.24 was the only game in town.

Have any of you guys accually installed and run BBC's upload.cgi?  Which was covered in the first 15 additions to this thread that now exceeds 100 threads.  There have been attempts to upgrade the code to 0.5 in this thread.  If you read this tread from the first and taken all the detours you deserve a mental heath award.

One last thought.  Why are we still thinking 0.24?

r

Re: File Uploading - A possible attempt

6epcepk wrote:

I have found mistake. I modified a script for work with xajax 0.5, and probably something has made not correctly. How you consider, whether expediently to use latest the version xajax?
Thanks for answers!

I should have a version for .5 beta 2 by the end of this week.

Re: File Uploading - A possible attempt

robertlam wrote:

Why not NOT create a random filename and instead name the upload the same name as the filename.  After all they are being sent to tmp storage.  Often the file uploaded name is inserted into a database with path info etc, etc.  When dealing with dozens or hundreds of uploaded files it's helpful to quitely id the uploaded file by it's name.  If your code is designed to upload one file by one guy then aok but if you want to have dozens of guys upload dozens of files at or about the same time maybe the approach should be to design upload as a php class.

Hi Robert.  Thanks for your post.
In response this first comment about the temp files.  Temp files are given a random name for the exact reason you have stated...in case there are many people uploading files at the same time.   Often, when an uploader is used in an app, it is to upload the same type of file and sometimes this same type of file will have the same name from one user to the next.  For example, in a site I am working on, it is very common for people to upload a file called export.fnm because a mortgage app spits that filename out by default.  So, if I was to only use the filename, wires might get crossed and somebody could run into major problems.  Secondly, my code provides for a method of taking the files out of their temp state and renaming them back to their original name, or for doing whatever you choose simply by writing your own function to handle a file array that includes all info you need to move, rename, delete, send to a db, or whatever you might need to do.  So, it is totally your choice on how you want to handle the files.  In my demo (and in the sample downloaded config file) the temp files don't even exist after the script completes.  Only the original file with the original file name is kept on the server, and that is what appears in the File Viewer.

robertlam wrote:

SI'm not sure why the last 10 or so update are in this thread.   Are we trying to re-invent the wheel? It's seems way off the the orginial essences, except for the word upload or perhaps it started when 0.24 was the only game in town.

Have any of you guys accually installed and run BBC's upload.cgi?  Which was covered in the first 15 additions to this thread that now exceeds 100 threads.  There have been attempts to upgrade the code to 0.5 in this thread.  If you read this tread from the first and taken all the detours you deserve a mental heath award.

One last thought.  Why are we still thinking 0.24?

r

I do have to appologize about posting a perl solution in BBC's thread.  Sorry BBC, you are working on something very interesting and if I had been better at following this thread, I would probably have tried to work with your php cgi instead of the one based on the megaupload perl solution.  Actually, I was probably one of the very first people to follow this thread in the beginning because I was looking real hard for a solution about a year ago.  As it turns out, I wrote this thing instead because I wanted something that was proven to work...and the perl solution was working great at that time.  Also, I should mention that I wrote the majority of this code about a year ago...so, I am out of the loop as far as php cgi AND .5 xajax.

I have no problem with somebody moving my posts off of this thread if that will help aid in the overall plugin mission.  I really recommend that anyone helping with the plugin continue BBC's efforts.

My reason for creating this was to have multi-file support and to have a speed control feature.  I just couldn't find anything that was production ready, and BTW, I still run 2.4 everywhere because I am one of those people who cannot afford to be bleeding edge/beta.

Sorry for making a long thread even longer!!   I will shut up now.  Anybody that wants to discuss my code please do so at my site http://trydobe.com.

Thanks,

jeremy

Re: File Uploading - A possible attempt

Hi tpneumat

You got me thinking....

You are right of course about the need to rename.  Lets follow the logic.  Two people attempt to each upload a file with the same name.  How would a program automatically attempt to save two files with the same name to the same folder.  It Can't.  Test for existing file with same file-name before or after attempted upload? 

So what to do?  Manually rename them by the thousands? How about first come first served.  There is no such thing as multitasking file saving.  It's always sequential.  Ok so up rename them but does the sender know how to associate your renameing to their filing system?  Maybe the solution is to make the file-name irrelevant.

But there maybe an auto  solution.  if you are using a database then there is no need to rename a random generated file-name.  All you have to do is associated the random file-name to the up-loader's type='text' title name of the file uploaded file.  But title type'text' parameters are not passed when you use enctype='multipart/form-data', method='POST' because it's not part of type='file'.  The type and value  are sent but are not linked.  We know that BBC's upload.cgi passes a random generated alfa-numeric that becomes part to the random generated file-name.  Maybe that's could be part of the solutions.  At least we can get at it via $stdin = fopen("php://stdin","r").  But that randomness happens before you submit the uploaded form. 

The nature of databases record uniqueness will prevent identical file-name associated with a user and of course concerns of identical name provided by two users becomes irrelevant.

So it may be possible, in one step, to require/request the uploader/sender' to provide a title for their uploaded file that becomes accessible via the Get method via $stdin = fopen("php://stdin","r") before the filename selection and send all that info to the parser.  Just as the 'file' info is placed in $_FILES so could the Title info be placed in a $_POST and turned to the remote server for processing. 

What are your thoughts about this approach?  Has anyone tried this?
r

Re: File Uploading - A possible attempt

Hi!
Has put @ to clean Notice on lines 105 and 106 files upload_xajax_inc.php.

Also there was a new mistake: "Upload Failed to begin.Your browser may not support this feature."
As I have understood, it arises owing to the big delay. Can be what adjustments CGI are not true on a local server?

Sorry for my bad English

Re: File Uploading - A possible attempt

6epcepk,

Please post your comments and questions about my script on my website trydobe.com.

Thanks,

Jeremy

Re: File Uploading - A possible attempt

tpneumat wrote:

I do have to appologize about posting a perl solution in BBC's thread.

I don't think there's any need to apologise at all.  In fact I think there should probably be a consolidated effort to work towards a file upload plugin for xajax.

Both the Perl and PHP methods have their drawbacks.  Eg the Perl solution will not run on server's that don't have Perl running, which is the reason I tried making a PHP cgi script, something that had not been done before.  Unfortunatly the PHP cgi may not always run, since it requires a particular setting in php.ini to work.

robertlam wrote:

Why not create a sub-group and deal with upload as a xajax plugin project.

This is a fantastic idea.  Is it worth starting up a seperate sourceforge project to do this?

robertlam wrote:

One last thought.  Why are we still thinking 0.24?

Why not have a solution that works with 0.2.x and 0.5?

tpneumat wrote:

Please post your comments and questions about my script on my website trydobe.com.

I'll post this reply there too ay?

Re: File Uploading - A possible attempt

BBC,

I would like to work with you on this.  Perhaps we could combine code and ideas for the xajax functions and the javaScript.  Then build both upload-perl.cgi and upload-php.cgi to accept the same parameters so that they are interchangeable, allowing the user to decide which they want to use.

I agree that the solution should work for both .2x and .5, but perhaps the implementation will have to be different.  Any thoughts?

tpneumat

Re: File Uploading - A possible attempt

tpneumat wrote:

I would like to work with you on this.

Great! smile  The one big thing that xajax seems to be missing out-of-the-box is file uploads.

I know that JaredWhite was keen to get a file-upload plugin going for v0.5.  Unfortunatly, the code I wrote was hacked together quickly as more of a proof-of-concept.

tpneumat wrote:

Perhaps we could combine code and ideas for the xajax functions and the javascript.

I like that idea.  I'll download another copy of your source code today and go over it in detail to see how you do things before I try to have any more thoughts on what to do smile

tpneumat wrote:

I agree that the solution should work for both .2x and .5, but perhaps the implementation will have to be different.  Any thoughts?

Hopefully not too different.  The v0.5 code branch has a legacyXajax and legacyXajaxResponse that allow the old v0.2.x commands.  Or we could possibly use some xajax version sniffing to see what version of xajax we're dealing with and have a quick wrapper of functions?  Doing that probably wouldn't work for including it as a plugin tho.  Hmm.. might have to think about this some more after work.

Re: File Uploading - A possible attempt

Cool.  I think if we pull this off and make it a simple plugin for xajax, it could bring a lot of people over to xajax.  PHP File upload utilities in general are in demand everywhere.  The biggest issues I am getting so far from people involve file permissions.  We will need to create clear instructions and permission requirements for installation.

-tpneumat

Re: File Uploading - A possible attempt

tpneumat wrote:

Cool.  I think if we pull this off and make it a simple plugin for xajax, it could bring a lot of people over to xajax.  PHP File upload utilities in general are in demand everywhere.  The biggest issues I am getting so far from people involve file permissions.  We will need to create clear instructions and permission requirements for installation.

-tpneumat

xAjax Upload 1.0.2.0.5 for xAjax 0.5's bug :
the script cannot filter files have whitespace so that user can select a file again and again
the problem should start from the line 115 in xajax_upload.js

See image

Re: File Uploading - A possible attempt

Hi, when I try this link

it only shows "Uploading..." after I click Browse and upload a file. Why does it happen? When I use it into my code, it happens the same things. Anyone can give me some hints? I'm using FF 2.

Re: File Uploading - A possible attempt

tootcsen wrote:

Hi, when I try this link

The upload script isn't there any more.

Re: File Uploading - A possible attempt

Wow, big thread!!!!

Where's the latest version of upload.cgi to be found?

Re: File Uploading - A possible attempt

Hello,

I can not get this to work on Firefox, neither the first option nor the second.
Using xajax.newFileUpload, just nothing appears; using xajax.initFileInputs, the file will not be send to anywhere.

What could be wrong?