XAJAX_UPLOAD: A Multifile PHP Upload with Status bar solution.

PLEASE READ LAST COMMENT BY ME BEFORE CONSIDERING USING THIS SCRIPT.

Here is a PHP Upload with Status bar.
Example Screen Shot
Demo 1 - Multi-File
Demo 2 - Single file/autostart upload.
Demo 3 - Xajax 0.5 working.

Download the Source Code:

Iconxajax_upload_1.0.1.zip (for xajax 2.4)


Iconxajax_upload_1.0.2.0.5.zip (for xajax 0.5)

 

WARNING: Many people have had trouble getting this script to run in a Windows hosted environment! I do not recommend this script if you are running it on Windows!

BACKGROUND: When uploading large files to a website using a browser, the lack of an upload progress bar can be the reason that somebody might just quit using your site. The user shouldn’t have to be thinking, “How long do I have to wait? Is it even uploading?”. When I decided to implement an upload status bar for a PHP site, I thought it would be as easy as browsing for an already built utility and simply adding it to the site. I was discouraged to find out that PHP 4.x had no native support for gathering statistics on the file while in the process of being uploaded. After some research, I found that there are really only a two options to achieve an actual readout of file progress. Like many solutions these days, both fall into the category of ‘nasty hack’, but what choice do we have?

The basis of the two solutions are:

1) Modify your actual PHP build on the server to include a patch. See http://pdoru.from.ro/. This wouldn’t work for me since the site was hosted on a shared server.

2) Use another technology besides PHP (in this case a CGI script) to handle the posting and reporting of the file status. This is the solution I chose to work with.

I looked around and found a few decent examples of respectable progress in the area of progress bars. Here are a few of my resources.

http://labs.beffa.org/w2box/demo/
http://www.obokaman.com/mensaje/1596/
http://tomas.epineer.se/tesupload/
http://www.raditha.com/megaupload/

Unfortunately, each example above was lacking in some way. To achieve the status bar updates, Ajax is the best solution, and popups are unacceptable if you ask me. Also, I didn’t want to have to depend on prototype or any other heavy helper. Finally, I really liked the multi-file system, but the method I found, although inspiring, was way too buggy and platform dependent.

SOLUTION: After mulling over these examples, (which included re-hosting some in an effort to see working demos), I was on my way to making something happen. However, there would be a few compromises and a lot of coding.

The solution outline would be as follows:

  • The file is posted from a form on the main page to a CGI script.
  • The CGI script is requested via a hidden iframe so the main page remains in its current state.
  • On the server, the CGI script reconstructs the posted file as it streams from the client.
  • From the main page, an Ajax request to the server calls a PHP function.
  • The PHP function measures the size of the file as it is being loaded.
  • The PHP function returns a response to main page Ajax handler and the progress bar is updated with javaScript.
  • This continues until the file has completed.
  • Once the file upload is completed, it can be manipulated by normal php file handling.

Luckily, I didn’t have to invent any of these concepts. But what I did do was reformat, flesh out, debug and simplify in order to make something that was more stable and easier to implement. I also added the following features.

  1. Speed control. You can limit the upload speed by designating a range between 1.0 and 10.0.
  2. Better Multi-File control. You can specify how many simultaneous files to allow for upload. If you have only 1 file uploaded at a time, you can turn on and off automatic submission of on selection.
  3. Better File Type control. You can either designate a list of file types to allow, or you can designate a list of file types to disallow if that is easier.
  4. Cancel Button. What if you started to upload the wrong file, and it is massive? Well, a person ought to be able to cancel and start over. Right? So be it.
  5. Max File Size Restriction. And ALL other settings do not need to be configured by modifying the CGI script. Everything is easily configured via PHP.
  6. CGI Debugging mode. Can’t figure out what is going on in the background? Turn on CGI debug mode to reveal the iframe and witness some helpful output.
  7. Prevent SSL Warnings in IE. Implemented a simple trick to prevent the SSL warning for unsecure content created by the iframe’s presence.
  8. Show/Hide Max file size messages. If for some reason you don’t want people to know what the max file size accepted is, then you can turn it off.

The example that I had of the multi-file upload tool was written with jquery. I think jquery is awesome, but I didn’t see any reason to make it a requirement for this task. I built off the concept I found and rewrote the JavaScript file to be free of dependencies and to support my new features and Ajax methods.

Finally, to handle Ajax, I prefer the xajax project. This is really the only addon requirement to make this work. I don’t think it would be too hard to adapt this utility to some other ajax handler.

FINAL WORDS:For the purist, this solution might seem cumbersome and unreasonable. But hopefully, practical folks will appreciate the fact that somehow it actually works. I have been using this upload utility in a few different production applications and I have had zero complaints. Yet, I wouldn’t be surprised if there are still bugs or compatibility problems here and there. I am looking forward to getting feedback on this. I will try to patch up anything that comes my way.

Enjoy!

- Jeremy Dill

TROUBLESHOOTING INSTALLATION:
Its not working! - First try setting $cgiDebug=1 and try uploading a small file and wait for output to appear. Perhaps you will get some information that can help. Also, please make sure that your xajax install is working before trying anything else. Use one of the test apps that come with the xajax package. If you don’t have it yet, get Firebug for Firefox. Use the Console, and in Options, enable ShowXMLHttpRequests. When the upload page is loaded, the first thing you should see is a Post (Request) with the function getSid. If there is no response, your xajax install is not working.

Upload Failed to begin.Your browser may not support this feature. -If cgi is executing and uploading the file but you still are getting this error sent back to the browser, then you may have a file permissions issue related to the location of temp files. If the php script cannot access the full path of the temp file, then it will never be able to run the file_exists test successfully, and therefore it will fail. Watch out for
1) php_admin_value open_basedir in your apache directives,
2) safe_mode=On or open_basedir in your php.ini

If cgi is not executing…the following applies.
For the top part of the page, if you are getting a “Preparing Upload” while underneath it says “Streaming ####_postdata” that means that the temp path is OK and readable. However, if it never finishes “Preparing” and ends up on “Upload Failed to begin”, then there is a problem somewhere else.

Most likely, cgi is not executing. if you have CGI debug on, you should see something in the debug box. If nothing is working, you should at least see a “Not Found - ” type error in the debug box. In that case, your cgi script is probably not reachable or possibly not executable. Basically, if you see Not Found in the iframe (debug box) then that means that your cgi script cannot be found and executed.

The proper place to put a cgi script is in the cgi-bin folder which is usually NOT within the web root (www or httpdocs). It is usually 1 level up from your httpdocs. If you don’t see it with your ftp client, create the folder and give rights 777. You should be able to do this via ftp even on a shared server.

Then, things to look for:

// PATH TO UPLOAD.CGI
$cgiPath=”/cgi-bin/upload.cgi”;

This needs to be set to a path reachable by your apache server and with the proper cgi directives configured. In my case, I have a in my Apache config file the following:

ScriptAlias /cgi-bin/ /var/www/cgi-bin/

This is a typical default setting if cgi is enabled on your server.

So, if the upload.cgi file is physically located at /var/www/cgi/upload.cgi, this ScriptAlias will make the cgi script reachable using the following url.

http://trydobe.com/cgi-bin/upload.cgi

Notice that if you open the link above, you will get no output, however you will also not get a Page Not Found error. That is because the page executed but there was nothing to output. Imagine the same behavior as running a php script with no output.

I recommend playing with the ScriptAlias and the $cgiPath settings to resolve your problem. It might help to install a test cgi script that spits out some text just to make sure you can execute cgi on your site.

Check out this link, as it may give some helpful tips on how to get the cgi to execute.

http://www.jmarshall.com/easy/cgi/easy_cgi_faq.html

unlink( ). Permission denied….Alerts and Warnings!! Blah Blah Blah. - Permissions are probably the biggest challenge to implementing this. Your script has to target folders that are permissioned to allow the cgi and php script to modify them. At the end of the script, files need to be cleaned up and moved around. Also, you need to consider the permissions of the folders used in your fileAction function. Correctly setting up permissions depends on how your server is configured, under what credentials your apache server runs, and what your tolerance is for public readable files on your server.

Please explain how the files in the temp folder are used.
Four files are created during a normal upload 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:

  • During the upload there will be 2 files (???_flength and ???_postdata).
  • When upload has completed, 2 more files are created (???_qstring and ???_signal).
  • 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

  • After the these files are created, the fileAction function is called and your files are manipulated in whatever way you have coded.
  • 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.

    REQUESTED FEATURES: - Future Releases

    • - Want to support more than one form per page.
    • - Want to submit along with other fields like description, etc.
    • - Rebuild as class and as xajax plugin.
    • - Want to utilize PHP 5.2’s (and above) native support for file upload status…eliminating cgi completely.
    • - Try to implement for Uber Upload instead of Mega Upload cgi.

    157 Responses to “XAJAX_UPLOAD: A Multifile PHP Upload with Status bar solution.”

    1. Martin Says:

      Hi Jeremy,

      your code is very initeresting!

      But it semms only to work with xajax 0.24. Is there also a version for xajax 0.5?

      Thanks and bye

      Martin

    2. Jeremy Dill Says:

      Martin,

      Thanks for your comment. I do not have a .5 version yet. I will adapt for .5. I was sort of waiting for the .5 to get out of beta, but check back in a week or so.

      Thanks,

      Jeremy

    3. Martin Says:

      Ok, fine! Thanks for your very fast answer!

      But now I am getting crazy with the programm and xajax 0.2.4.

      The Apache has definitley the right to write to the /temp directory, but the script always tells me “Upload Failed to begin…”

      In the red box there is “Streaming 8dcda5be161e9aadb05f10f436f4e275_postdata” and in the debug box there is “Not Found - The requestet document was not found on this server”

      I think that the script is not able to upload the file to the temp directory.

      The cgi file has 755, all xajax files are available and the destination directory has 666.

      I can change anything in the php.ini, but was not able to run the script.

      I have tried 1000 things for hours now. Do you have any other ideas?

      Thanks a lot!

      Martin

    4. Jeremy Dill Says:

      For the top part of the page, if you are getting a “Preparing Upload” while underneath it says “Streaming ####_postdata” that means that the temp path is OK and readable. However, if it never finishes “Preparing” and ends up on “Upload Failed to begin”, then there is a problem somewhere else.

      In your case, the “Not Found - ” error is the clue to solve the issue. Basically, if you see Not Found in the iframe (debug box) then that means that your cgi script cannot be found and executed.

      Things to look for:

      // PATH TO UPLOAD.CGI
      $cgiPath="/cgi-bin/upload.cgi";

      This needs to be set to a path reachable by your apache server and with the proper cgi directives configured. In my case, I have a in my Apache config file the following:

      ScriptAlias /cgi-bin/ /var/www/cgi-bin/

      So, if the upload.cgi file is physically located at /var/www/cgi/upload.cgi, this ScriptAlias will make the cgi script reachable using the following url.

      http://trydobe.com/cgi-bin/upload.cgi

      Notice that if you open the link above, you will get no output, however you will also not get a Page Not Found error. That is because the page executed but there was nothing to output. Imagine the same behavior as running a php script with no output.

      I recommend playing with the ScriptAlias and the $cgiPath settings to resolve your problem. It might help to install a test cgi script that spits out some text just to make sure you can execute cgi on your site.

      Check out this link, as it may give some helpful tips on how to get the cgi to execute.

      http://www.jmarshall.com/easy/cgi/easy_cgi_faq.html

      Good luck. And thanks for the feedback. It probably helps others too!

    5. Martin Says:

      It works!!! Thanks a lot!

      The problem was indeed the wrong path to the CGI script. I used the whole path on the server (/home/httpd/vhost/domain/cgi-bin/upload.cgi), but you should only use the path of the domain (/cgi-bin/upload.cgi).

      Also very important for Plesk 7.5.4 users is the fact, that the script file MUST have 755 rights (not 777!) and it MUST belong to the group psacln (the owner doesn’t matter)! Otherwise the CGI script will not run.

      Thanks again for the great work!

      Martin

    6. Peter Says:

      Hello!
      your uploading tool looks nice and i had tried to implement it. I’m not so familiar with cgi scripts so i think i have a problem there.
      I’ve got the form on my site and i can add files through the download input. But when i press send i first got “preparing upload” and then i got a failure “Upload Failed to begin.Your browser may not support this feature”. But i use the newest Firefox. So this can’t be the problem. Any idea what this could mean?
      thx for helping
      bye

    7. Peter Says:

      Sry hadn’t tried the debug. The debug tells me Streaming 1174984478342e99ca89932c8586f42e_postdata and if the cgi has 750 i got “You don’t have permission to access /xajax/Upload/upload.cgi on this server” and if th cgi has 755 a download action is startet where i can download the cgi script. I hope you can help me!
      thx, bye

    8. Jeremy Dill Says:

      Peter,

      It seems that maybe you don’t have perl/cgi available on your server (at least not in the url you have specified). What kind of server do you have? Is it apache or IIS?

      Jeremy

    9. Peter Says:

      Thx for your fast answer, it is an apache server. Does the phpinfo tell me if i have cgi or not? Because its not my server and i just work on it i don’t know exactly where to put the cgi and if the server supports it.
      peter

    10. Jeremy Dill Says:

      Peter, in your phpinfo, look for Loaded Modules. Do you see mod_cgi and mod_perl? If so, then its probably workable, but you probably have the cgi script in the wrong place. You need to put the cgi script in on the server in whatever location is specified by ScriptAlias in the Apache config files.
      Normally, this is defaulted to a folder at the same level as your wwwroot folder named cgi-bin, but it can be any place. You have probably already demonstrated through your experiment described above (where the browser prompts for a download of the file) that you cannot put the cgi file in a folder within your website.

      So, try putting the cgi script in a folder called cgi-bin located in the parent folder of your web root on the same level as wwwroot (or sometimes httpdocs). If the cgi-bin folder doesn’t exist, create it. Then set the permissions to 755. Finally, try setting the
      // PATH TO UPLOAD.CGI
      $cgiPath="/cgi-bin/upload.cgi";

      in upload_config_inc.php.

      If this doesn’t work, then you may need to work with the administrator of the webserver to find out how to install cgi scripts.

      Did you read this? http://www.jmarshall.com/easy/cgi/cgi_footnotes.html#placing

    11. 6epcepk Says:

      Hello, Jeremy Dill!
      If I add a delay in function “uploadHandler” after “$objResponse = new xajaxResponse();”, loading of a file occurs normally, differently there is a mistake: ” Upload Failed to begin. Your browser may not support this feature. ”
      In what there can be a problem? Thanks.

    12. Jeremy Dill Says:

      6epcepk,

      Have you tried increasing the $startDelay setting in the upload_config_inc.php


      // START DELAY (IN MILLISECONDS). INCREASE THIS TIME IF THE CGI SCRIPT SEEMS TO BE WORKING, BUT THE UPLOAD HANDLER APPEARS TO HAVE FAILED.
      // IF THE AJAX TIMESOUT BEFORE THE FILE UPLOAD STREAM BEGINS, THE CLIENT DIDNT WAIT LONG ENOUGH AND UPLOADING WILL APPEAR TO HAVE FAILED.
      $startDelay="1000000";

      Try setting $startDelay to 2000000 or 3000000.

      ~Jeremy

    13. 6epcepk Says:

      Yes, tried.
      Has now tried to expose $startDelay = “999999999999999999999999999999999999″; but all the same without results.

    14. Jeremy Dill Says:

      6epcepk,

      This is difficult for me to troublehshoot because I am not sure what your environment is like. Are you hosting locally? What browser are you using? What version of php?

      When you put the delay in, what is your exact code. Are you using usleep or sleep? Also, how quickly does the error “Upload Failed to begin….” appear if you do not modify the uploadHandler function? Does it fail immediately, or does it take a few seconds to fail, while appending dots (…) to the “Preparing Upload”. You should see a new period (.) appear after “Preparing Upload…” every second (or whatever milliseconds you set for $startDelay). This should continue until either 1) the upload begins, or 2) Five periods appear and the upload fails.

      Please let me know in what manner it fails. I am wondering if there might not be an issue with your globals not being available. Make sure that $xajax->processRequest();” comes AFTER the require(”upload_config_inc.php”); in your main page. If you turn cgiDebug on in the config, does it create a visible iframe? If not, then I would say you have some issue with global vars not accessible by the uploadHandler.

      Thanks,

      Jeremy

    15. 6epcepk Says:

      Yes, I test on a local server with PHP-version 5.

      After pressing the button of loading instantly there is a message on the mistake, the established delay does not influence in any way.

      Checked on Opera 9 and Firefox (minefield).

      I test on main_page_sample.

      Thanks for answers!

    16. Jeremy Dill Says:

      6epcepk,

      I am thinking that for some reason your global variables are not accessible by the uploadHandler. Did you try setting $cgiDebug=1. If you see the iframe, then my theory is wrong. But if you don’t see the iframe (like it shows in http://trydobe.com/xajaxupload/demo3/), then somehow we need to figure out why your globals are not accessible by the xajax function.

      thanks,

      jeremy

    17. 6epcepk Says:

      Yes, I see debug-frame.

      Now I have exposed compulsory sleep for one second - all works perfectly.

      Who is interesting to hear opinions in general worked with the given plug-in or not.

    18. 6epcepk Says:

      Now in my system one of the variants offered at a forum xajax is used. Whether It is possible to add in your variant additional fields to each file without additional editing initial files?
      Thanks!

    19. Jeremy Dill Says:

      Sorry, but I don’t understand. :(

    20. 6epcepk Says:

      For example, I need to load pictures. Each picture has a name etc.

    21. robertlam Says:

      Hi Jeremy

      Do you know where axactly 6epcepk put the sleep in the code?

      r

    22. robertlam Says:

      I also wanted to ask about the foo.html. I see where it’s being use in the iframe but what is it’s role? What permissions settings? etc…

      r

    23. robertlam Says:

      Hi Jeremy

      where is $tmpDirInCGI to be set?

      Also am i correct that if you set
      $showMax=1;
      $maxFiles=1;

      that i should not see the send button?

      r

    24. Jeremy Dill Says:

      6epcepk, I think I know what you mean. Actually roberlam and I have been talking about this. I believe you would like sort of an “upload as” feature that lets you change the name before submitting the upload? Maybe in a later release. It is complicated by the multi-file nature of the submission.

      Thanks,

      Jeremy

    25. Jeremy Dill Says:

      robertlam,

      I do not know exactly where 6epcepk was sleeping the code, but I think it should not be necessary. There are already sleeps in the code designed to handle the issues with timing. These are $startDelay and $refreshDelay. If these aren’t working for some people, I would rather figure out why and fix them rather than adding a sleep to the xajax function.

      As far as foo.html. It should be placed anywhere in your site accessible by any user of your site. For example, http://trydobe.com/xajaxupload/demo3/foo.html. It is a feature that is only used to prevent IE from prompting the user about unsecured content when the user is both using IE and your file uploader is on an ssl site. You can comment out $blankHTMLPath, and even get rid of foo.html if you are NOT using SSL.

      If you set
      $showMax=1;
      $maxFiles=1;
      You will still see send button. If you want to hide the send button, set
      $autoFirst=1.

      about $tmpDirInCGI… I accidentally left this out of release 1.0.1.0.5. It is not included in the updated config in 1.0.2.0.5. - Sorry for the confusion.

      Hope this helps. I am working with you on your other problems via email…we may have to post our findings here.

      -jeremy

    26. robertlam Says:

      Hi Jeremy

      As it turns out your cgi works as advertised but you may want to mention that permissions should be 0777/0770 on the uploadtmp folder. I changed the chown&chgrp to user nobody. This solution was the last place i would have looked. I’m still freaking out 0777….

      thanks for everthing.

      r

    27. robertlam Says:

      Hi Jeremy

      New business.

      I am working on the two forms one button solution. I saw some chatter about this idea earlier today.

      one form in an iframe the second form not. using this approach.




      in form ‘a’ do the upload and expose the $_FILES info to form ‘b’ on return.
      In form ‘b’ place name=title value=myMoive etc and $_FILES info to database. No need to change tmp filename. Also tmp folder can become the destination folder no need to move or change the name.

      Before i go fishing do you know if this has been invented by a javascript or xajax player?

      r

    28. Jeremy Dill Says:

      robertlam,

      I cannot see a very compelling reason to return the file info back to the browser (into form b). It would be easier to do everything on first submission. Basically, what people are asking for I think (and please confirm or deny this) is a way to do the following: 1) Select your files. 2)and Before submit, change the name of the files or put a description next to them, etc. 3) and finally, have that info (new file name and description) be associated with the temp file name and be available in the final fileAction. So, we want this.


      $fileArr['tmp_name'] IS THE FULL PATH OF THE TEMP FILE INCLUDING THE UPLOAD DIR. (EXAMPLE: "/var/www/uploadtmp/IZsCKzFXEL")
      $fileArr['name'] IS THE ORIGINAL NAME OF THE FILE (EXAMPLE: "05 - Herald! Frankenstein.mp3")
      $fileArr['size'] IS THE SIZE IN BYTES OF THE FILE (EXAMPLE: "1138816")

      $fileArr['newname'] IS THE NEW NAME CHOSEN FOR THIS FILE BY THE SUBMITTER (EXAMPLE: "Frankenstien.mp3")

      $fileArr['description'] IS A DESCRIPTION WRITTEN BY THE SUBMITTER FOR THIS FILE. (EXAMPLE: "This is my favorite song!")

      If you have all of that passed to fileAction, you could easily insert the linking info into a database, move files to another dir, create xml labels, build html output…. whatever you heart desires. I don’t want to code anything for this utility that is specific to on person’s requirements. That is why fileAction function is in the config file. It is called at the end of the upload process and the completed multi-dimensional $fileArr is passed as its parameter. So you can do whatever you want to the files after the upload has completed.

      As far as implementing a renaming and description feature, I think I will try to use xajax’s getFormValues, specifying a prefix thereby allowing me to keep the name and description elements in the same form. I don’t think there is an advantage to 2 forms. ..got to go.

      ~Jeremy

    29. ugjcm Says:

      Good site!!!

    30. Ludo Says:

      now with php 5.2 and Hooks for tracking file upload progress.
      the cgi could be remove with some modification.
      Thank you for the work , it is a good and nedded features to xajax

    31. Jeremy Dill Says:

      Thanks Ludo!. I have recently learned about that. I am actually trying to get my server up to 5.2 now to test some things out.

    32. Jon Says:

      I am using the 0.24 version and it works great! But I have a question about your recommended settings for the .htacess file. What is the purpose of each line and in which folder should the file reside?

    33. Jeremy Dill Says:

      Jon. Good question, and sorry I don’t explain that anywhere. The .htacess file setting should be done if you don’t have access to modify (or don’t want to modify) the php.ini file. The settings are as follows:


      php_value post_max_size 50M -Maximum size of POST data that PHP will accept.
      php_value upload_max_filesize 50M -Maximum allowed size for uploaded files.

      By default, in a typical php install, these are set to 2M. That means, that if you change the upload_config_inc maxFilesize to something greater than 2M, you will find that it is still limited to 2M. You need to set this to at least the highest setting you would be putting in your upload_config. To see some details about your system max file size settings, try uncommenting out the stuff under “// FOR DEBUGGING OVERALL MAX FILESIZE LIMIT” in the upload_config_inc.


      php_value memory_limit 50M ; Maximum amount of memory a script may consume

      Actually, this may or may not be necessary. But if you find that you are getting errors like “Allowed memory size of ###### bytes exhausted (tried to allocate ## bytes).” when running the php code, you will need to increase your memory_limit either in htacess, or in php.ini. I haven’t tested to see exactly how much memory should be needed, but I am pretty sure that 50M is overkill. The default is 8M usually I think.


      php_value magic_quotes_gpc 0 -Magic quotes for incoming GET/POST/Cookie data.

      Come to think of it, since the post goes to cgi, this change may not be required at all. I will probably remove this recommendation in future versions.

      Thanks,

      Jeremy

    34. dolittle Says:

      Hi,

      I`m running Apache local server (xampp) on windows XP.
      First I had to add the perl add on to the basic xampp installation.
      Then I had to change the upload.cgi first line to be compatible with the perl path on windows.

      Everything seem to work but I can`t see the uploaded file.
      I see the message, the progress bar, everything but no file.

      Maybe I don`t replace these lines properly:
      rename($fileArr[’tmp_name’][$x],”/var/www/uploadtest/”.$fileArr[’name’][$x]);
      rename($fileArr[’tmp_name’][$x],”/var/www/vhosts/trydobe.com/files/uploadtest/”.$fileArr[’name’][$x]);

      I`m trying:
      move_uploaded_file($fileArr[’tmp_name’][$x],”upload/”.$fileArr[’name’][$x]);

      When I`m trying a simple example to see if I have write permission
      it works fine:
      http://www.w3schools.com/php/php_file_upload.asp

      Is there a way I can pause the script to check if the temp files are being created?
      Do you have a suggestion of what I`m doing wrong?

      Thanks

    35. Jeremy Dill Says:

      dolittle,

      It does sound like something is failing in your fileAction, otherwise you would get an error. I have 2 suggestions. One, you shouldn’t need to use move_uploaded_file because $fileArr[’tmp_name’] will be referring to a physical file on the server, and not a posted file. The posted file is already transformed into an actual file. So rename should work. The other thing that I would suggest is that you try windows file syntax. In other words, try something like

      rename($fileArr[’tmp_name’][$x],”C:\\upload\\”.$fileArr[’name’][$x]);

      - jeremy

    36. Martin Says:

      Hi Jeremy,

      now I have switched to the xajax 0.5 version and xajax_upload 1.0.2.0.5.

      When I start to “send” a file then the following happens:

      - “upload initiated”
      - red box: “Streaming 8b65d9ab51690c5a7531fd207a7c4b81_postdata”
      - “Preparing upload”
      - debug box: “Internal Server Error”
      - “Upload Failed to begin. Your browser may not…”

      The 0.2.4 version worked very well, so I don’t think that there is a problem with the rights or the paths.

      I have installed PHP 4.3.3 under Suse Linux.

      Do you have an idea?

      Thanks again and kind regards,

      Martin

    37. Martin Says:

      Hi again,

      I don’t know why, but it works now. Though I changed nothing…

      Sorry for disturbing.

      Martin

    38. 6epcepk Says:

      Good afternoon. Today I have established the system on the second hosting. But the unknown mistake has been found out: the frame if the cgiDebug = 1 was not created.

    39. Jeremy Dill Says:

      6epcepk,

      Maybe you need a miracle like Martin :)

      Sorry, but I would need to know more information before I could help solve that one. I know that setting cgiDebug to 1 exposes the iframe if everything is setup properly. Chances are, you are getting some other kind of error that is preventing the iframe from ever being made. “startOver()” is probably not executing properly. Look for javascript errors in your firefox console. Maybe there is a clue there.

      - Jeremy

    40. Dilip Says:

      when i access the page main_page_sample.php….

      i got a Notice from php….
      Notice: Undefined variable: onload in /var/www/html/develop/Dilip/PHP/xajax_upload/upload_config_inc.php on line 206

      along with an error from xajax in an alert box which contains….
      Error: the XML response that was returned from the server is invalid.
      Received:
      Notice:: undefined variable: onload in…..blah blah……..

      so when i checked the file upload_config_inc.php, there is an entry like this
      $onload .=”startOver();”;
      actually what is the need of a dot (”.”) operator in the above statement……???

      so i removed that dot and accessed the page…..
      then it loaded without showing any errors…

      when i select one file and click the SEND button…
      xajax returned the following error message in an alert box……

      undefined variable i in upload_xajax_inc.php on line 139
      undefined variable dots in upload_xajax_inc.php on line 139…..blah blah…..

      pls help me out….

    41. Jeremy Dill Says:

      Dilip,

      Nice name. Anyway, you need to have Notices turned off in your php config or you will find a lot of problems with ajax requests in general. Notices are harmless and normally do not get outputted unless you turn all errors and notices on in php.ini.


      // Report all errors except E_NOTICE
      // This is the default value set in php.ini
      error_reporting(E_ALL ^ E_NOTICE);

      Pulled from:
      http://us2.php.net/error_reporting

      BTW-
      $onload .=”startOver();”; is perfectly valid syntax. It is shorthand for $onload=$onload.”startOver();”;
      The Notice is thrown because i don’t use $onload before trying to append to it. Fixing this isn’t enough, however, because there will be more undefined vars in the xajax calls, creating header outputs which kill the nicely formatted xml responses, snowballing into disaster.

      - Jeremy

    42. Dilip Says:

      hey buddy….
      thnx 4 ur reply…

      i hav turned off php notice…
      so when i clicked send…
      it shows
      Streaming 6c….._postdata
      Upload Failed to begin.Your browser may not support this feature.

      pls help me….
      this is my config..

      $uploadDir=”upload/”;
      $tmpDirInCGI=0;
      $cgiPath=”cgi/upload.cgi”;
      $xajaxRoot=”xajax”;
      $blankHTMLPath=”foo.html”;
      $maxFilesize = “5M”;
      $showMax=1;
      $maxFiles=3;
      $autoFirst=0;
      $uploadSpeed=5.1;
      $extMode=0; $fileTypes=”exe,cgi,bat,cmd,com,asp,php,key,dll,sh,pl”;
      $refreshDelay=”500000″;
      $startDelay=”1000000″;
      $cgiDebug=1;
      set_time_limit(100);

      is it necessary to put the cgi file in cgi-bin directory…??
      in this case, i have created a cgi directory in my folder and put upload.cgi in that directory…..and give this path in the config file….is it ok…???
      becoz i’m currently working in a shared environment…

      waiting 4 ur reply…

    43. Jeremy Dill Says:

      Dillip,

      For the top part of the page, if you are getting a “Preparing Upload” while underneath it says “Streaming ####_postdata” that means that the temp path is OK and readable. However, if it never finishes “Preparing” and ends up on “Upload Failed to begin”, then there is a problem somewhere else.

      In your case, if you have CGI debug on, you should see something in the debug box. If nothing is working, you should at least see a “Not Found - ” type error in the debug box. In that case, your cgi script is probably not reachable or possibly not executable. Basically, if you see Not Found in the iframe (debug box) then that means that your cgi script cannot be found and executed.

      The proper place to put a cgi script is in the cgi-bin folder which is usually NOT within the web root (www or httpdocs). It is usually 1 level up from your httpdocs. If you don’t see it with your ftp client, create the folder and give rights 777. You should be able to do this via ftp even on a shared server.

      Then, things to look for:

      // PATH TO UPLOAD.CGI
      $cgiPath="/cgi-bin/upload.cgi";

      This needs to be set to a path reachable by your apache server and with the proper cgi directives configured. In my case, I have a in my Apache config file the following:

      ScriptAlias /cgi-bin/ /var/www/cgi-bin/

      This is a typical default setting if cgi is enabled on your server.

      So, if the upload.cgi file is physically located at /var/www/cgi/upload.cgi, this ScriptAlias will make the cgi script reachable using the following url.

      http://trydobe.com/cgi-bin/upload.cgi

      Notice that if you open the link above, you will get no output, however you will also not get a Page Not Found error. That is because the page executed but there was nothing to output. Imagine the same behavior as running a php script with no output.

      I recommend playing with the ScriptAlias and the $cgiPath settings to resolve your problem. It might help to install a test cgi script that spits out some text just to make sure you can execute cgi on your site.

      Check out this link, as it may give some helpful tips on how to get the cgi to execute.

      http://www.jmarshall.com/easy/cgi/easy_cgi_faq.html

      Good luck.

    44. James Says:

      I can’t figure this one out. I know that the upload.cgi is being executed and if I upload some decent sized files I can see them in the tmp upload directory during the upload process. The problem appears to be that the array that gets passed to fileaction() is empty. Any idea what may be happening here?

      Here is what I’m running. Maybe that will help.

      Server version: Apache/2.0.59
      PHP 5.2.0
      This is perl, v5.8.6 built for i386-linux-thread-multi

    45. Newbie Says:

      Hello,
      I used the script and I got this error : “Encountered error: Unable to open numfile:No such file or directory. Also unable to write to error file.” What does it mean and how do I fix this ? Thanks very much.

    46. Jeremy Dill Says:

      James,

      Just a quick thought

      fileaction typically deletes the final temp files like

      8umW8ufifQ
      NuegZoOQ1o
      tGoZxfdVjf

      Are these are still in the folder when the script is done? If not, then fileaction CLEANUP code must be working, thus the arr is passed and something else may be wrong with fileaction. Also, I haven’t tested this on PHP 5.20. I guess it is possible there is a problem there.

      - Jeremy

    47. Jeremy Dill Says:

      Newbie,

      That error comes from the cgi script..basically, cgi script can’t write to the temp folder that you specified in $uploadDir. Also, make sure you are setting $tmpDirInCGI=0; unless you have modified the cgi.

      thanks,

      -Jeremy

    48. Newbie Says:

      Jeremy Dill,
      I am still in problem. I’m using XAMPP for Windows so I modified the first line in the CGI script to :

      #!c:/Program Files/xampp/perl/bin/perl.exe

      and

      $uploadDir=”c:/Program Files/xampp/htdocs/”;

      Both this paths are correct but I can’t get the script work :( . Please I’m need help. Thanks very much.

    49. Newbie Says:

      Ok, I modified the CGI script :

      $tmp_dir= “c:/Program Files/xampp/htdocs/”;

      and in the PHP script :

      $tmpDirInCGI=1;

      Files were uploaded but they were temp files : NKdYdDXKae, im8xSrDsd1 … and the PHP script didn’t show the progress bar. What was the problem and What I have to do now to fix this ?

    50. Jeremy Dill Says:

      Newbie. Although I haven’t done any testing of this code in a windows environment, I can’t think of why it wouldn’t work except for issues with path and permissions. If you get no status from the progress bar, then php isn’t reading or finding the temp dir that your cgi script is now using. At first glance, it looks like your syntax is wrong for windows paths. Windows uses backslashes instead of forward slashes. I think that $uploadDir=”c:/Program Files/xampp/htdocs/”;

      Should be

      $uploadDir="c:\\Program Files\\xampp\\htdocs\\"; (double backslashes are needed for escaping.)

      While, you would still need to use forward slashes for $cgiPath=”/cgi-bin/upload.cgi”; since that is a url. Finally, in your in your fileaction, you need to modifiy the rename($fileArr[’tmp_name’][$x]… to use window paths also.

      -jeremy

    51. Newbie Says:

      Bravo ! The script worked :) and it showed : “Upload has completed” when the upload finished. Finally, I concluded that if I want to use this script in Windows that I should :

      *Install mod_perl.

      *In upload_config_inc.php :
      + $uploadDir=”path/to/upload/dir”; // Forward Slash “/”
      + $tmpDirInCGI=1;
      + rename($fileArr[’tmp_name’][$x],”path/to/upload/dir”.$fileArr[’name’][$x]);

      *In upload.cgi :
      + The first line : #!path/to/perl.exe
      + $tmp_dir= “path/to/upload/dir”;

      And, thank you, Jeremy Dill, very much for your devoted help :D

    52. Jeremy Dill Says:

      Newbie,

      Glad it worked for you! Interesting that you needed to use forward slashes in windows environment. I will keep that in mind for later instructions.

      - Jeremy

    53. Steve Says:

      Hi,

      I am getting this error. Any Ideas what is wrong?

      uncaught exception: [Exception… “Component returned failure code: 0×804b0012 [nsIDOMHTMLFormElement.submit]” nsresult: “0×804b0012 ()” location: “JS frame :: http://csidev1.com/lra_quality/xajaxgrid/upload/xajax_upload.js :: postIt :: line 61″ data: no]

    54. Steve Says:

      Ok It was a cgi config problem now i get
      Upload Failed to begin.Your browser may not support this feature.

    55. Jeremy Dill Says:

      Steve,

      Please see my comment above to dilip dated 22 April 2007, 8:06 pm.

      - Jeremy

    56. Steve Says:

      Hi,

      Thank you for your tips! It works now. this is a really nice file upload.

    57. Newbie Says:

      Hello again. I’m having problem with the html code. I copy the upload form to my page and then, after choose file, the form doesn’t show the list of file and the button Send still disabled. That look like something wrong with the Javascript code. I check many times that I have done the 10 steps in the file main_page_sample.php. Please help me. Thanks.

    58. Jeremy Dill Says:

      Newbie,

      Have you checked out the troubleshooting instructions I listed starting with “Its not working! “. Use Firebug to make sure that there are no js errors and to make sure getSid xajax function fires on page load.

    59. Newbie Says:

      I used Firebug and I got this :

      sid=’4eeb1b99435c81e6c4d34c92a97118a5′;
      Node was not found” code: “8

      What does it mean ? Can you explain it for me please ?

    60. Newbie Says:

      Sorry, I forgot :

      sid=’deea0198001a1587e91590fb10f7c2a7′;

      This in the xajax_core.js line 168.

    61. Jeremy Dill Says:

      I am sorry, you would need to post your entire page for me to solve that one. Did you get the the demo to work with the basic main_page_sample.php supplied?

    62. Newbie Says:

      Hmm, I have found what the problem is. I am using a JS script called DHTML Window :
      http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

      I set the style : .uld to display:none; and I use the JS script to show the form that this action make the files don’t appear in the page. Can you give me another idea for this ? I’m need both of your script and the DHTML Window JS script.

    63. Min Says:

      HI ..,

      When I try to setup, i got the error message
      “Unable to write-lock numfile:” from upload-cgi .
      I think it is something to do with chmod of that file, folder and temp folder chmod.

      Please highlight to me what is the proper chmod for this.

    64. Min Says:

      hi ..

      Please help me,I got the following error
      Unable to write-lock numfile:

      I think it is something to do with chmod.
      Currently i set it to 755. What is the corrct chmod for upload.cgi and temp directory

      Thanks ,

    65. ninetum Says:

      Hi, Jeremy

      when i run i get this error
      in the red box :Streaming 618c21b59bc2bbeab978f4e59192f265_postdata

      below the progress bar : Upload Failed to begin.Your browser may not support this feature.

      in the iframe : Internal Server Error
      The server encountered an internal error or misconfiguration and was unable to complete your request.

      Please contact the server administrator, XXX_XXXXXX@hotmail.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

      More information about this error may be available in the server error log.

      ——————————————————————————–

      Apache/2.2.4 (Win32) PHP/5.2.1 Server at localhost Port 80

      When I run http://localhost/cgi-bin/upload.cgi? I get Internal Server Error same as in the iframe

      plz help me !!!!!
      thank in advance

    66. Newbie Says:

      Too bad, no reply then !

    67. Jeremy Dill Says:

      Sorry I have been very busy and no time to help here.

      Newbie, I am sorry but I am not able to support your question because it falls out of scope for this project. Your implementation of the code is just that…your implementation. CSS and js are complex and unless you post specific code and ask specific questions, any answer I provide will just be a guess.

      - Jeremy

    68. Jeremy Dill Says:

      Min,

      Unfortunately, unless you are using facls or managing group or user permissions in a way that specifically targets the service account that executes the cgi, you will find that you will need to give permissions of 777 to the temp folders. Try that and let me know if it works. Start with more open to get it working, then try restricting accounts/group permissions until it breaks.

      -Jeremy

    69. Jeremy Dill Says:

      ninetum,

      Please see my comment above to dilip dated 22 April 2007, 8:06 pm.

      - Jeremy

    70. Newbie Says:

      Jeremy Dill, here is the source :
      http://www.zshare.net/download/code-zip.html
      Please … I can’t wait any more :(

    71. Jeremy Dill Says:

      Newbie,

      http://trydobe.com/test/1/

      I put your files on my site. Basically, for some reason, calling the dhtmlwindow.open thing is seems to kill the the javascript that is tied to the onchange event of the upload form. I made it work by calling startOver() again after running your dhtmlwindow.open command.

      onClick="divwin=dhtmlwindow.open('divbox', 'div', 'uploadform', 'Upload Files',
      'width=400px,height=300px,resize=0,scrolling=0,center=1');
      divwin.moveTo('middle', 'middle')  startOver();return false;
      

      Sorry I cannot help you much beyond this. I have 2 jobs and I am also running a business at the same time. Try breaking things down to troubleshoot these things.

      I am wondering why you moved the stuff out of the config file ($frmOut and $styleOut;) and put them in your main page.? I put it back in the config so I could more easily troubleshoot.

    72. Newbie Says:

      Thank you very much for your help that I need only this ! I’m thinking of writing a new documentation for your script that will explain more detailed.

    73. ninetum Says:

      Jeremy,
      I’m using an apache server on microsoft window. When I look in my phpinfo load modules I see mod_cgi but not mod_perl. Do I need mod_perl to run your cgi script? I install ActivePerl 5.8.8 build 820 and test on simple cgi script like print hello world and it can run. But I can’t get your upload.cgi to run.

    74. Newbie Says:

      Have you seen my comment on 30 April 2007, 7:15 am ? I’m using Windows and I prefer to use XAMPP because it’s easy to use and has many addons that fit for you. You can download it here :

      http://www.apachefriends.org/en/xampp-windows.html

      Download both XAMPP and Perl installer.

    75. bodoha Says:

      Hi Jeremy,

      when I try to download one of the above versions, I get always following errors:

      Warning: filesize(): open_basedir restriction in effect. File(/var/www/vhosts/trydobe.com/files/downloads/xajax_upload_1.0.2.0.5.zip) is not within the allowed path(s): (/var/www/vhosts/trydobe.com/httpdocs:/tmp) in /var/www/vhosts/trydobe.com/httpdocs/tools/fileget2.php on line 13

      Warning: fopen(): open_basedir restriction in effect. File(/var/www/vhosts/trydobe.com/files/downloads/xajax_upload_1.0.2.0.5.zip) is not within the allowed path(s): (/var/www/vhosts/trydobe.com/httpdocs:/tmp) in /var/www/vhosts/trydobe.com/httpdocs/tools/fileget2.php on line 15

      Warning: fopen(/var/www/vhosts/trydobe.com/files/downloads/xajax_upload_1.0.2.0.5.zip): failed to open stream: Operation not permitted in /var/www/vhosts/trydobe.com/httpdocs/tools/fileget2.php on line 15
      The file could not be found on the server.

      Can You help, please?

    76. Newbie Says:

      hello,
      i’m doing a little style modification. can you tell me where and how can i change the style of the “Browse…” button please ? thanks

    77. Newbie Says:

      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

      http://img482.imageshack.us/img482/1014/untitledyn9.png

    78. Jeremy Dill Says:

      Bodoha et al. Sorry. Had some very strange hosting issues. Download should work now.

      Newbie, It is not possible to change the style or the text of the html file upload form Browse button. There are ways to mask the button by floating div’s over the top, but there is no way to actually style it. Dunno why, but that is just how it is. Search around the internet and see what I mean.

      Newbie, thanks for the bug notice.

    79. Newbie Says:

      Jeremy Dill,
      I see, although it’s unable to change the input style but there are hacks to do this. Here is an example :

      http://www.quirksmode.org/dom/inputfile.html

      Hope this will be useful.
      Newbie,

    80. tootcsen Says:

      Hi, I’m using xajax 2.5, is it possible xajax_upload 2.4 used in 2.5?

    81. Jeremy Dill Says:

      tootcsen,

      I think 2.5 should work. Let me know otherwise.

      Thanks,

      Jeremy

    82. Amjith PS Says:

      Great code dear… Nice work! i dont use yeat but i saw ur demo’s feels reallt intresting .. and i will try to use in my new works and will send you feed back. Carry on R&D and the best!! ;^)

    83. Dan Says:

      Hi,

      This is a great tool! Thank you so much. It took me a while to get it working, but now that it does I’m very happy.

      You mentioned that it would be possible to input other information along with the file, such as a description of the file or anything else. I would love to be able to save such information to my MySQL database as I could do which a regular upload form. I know you do not have the time to code this, but I am fairly new and would love to know where I need to start - meaning: where can I find the code for the form so that I could add this feature?

      Thank you for any help you can give.

      Dan

    84. Dave B Says:

      This looks great, but I’m going over the code trying to figure out how I can modify it to support multiple uploaders on a single page, where each uploader has its own configuration and destination path.

      Has anyone done this yet?

    85. Jeremy Dill Says:

      Dan, the form itself is built into the in $frmOut var in the upload_config_inc.php. To make the description mod, you would have to mod $frmOut, and also probably have to mod the javascript in xajax_upload.js to show/hide where needed. I haven’t put a lot of thought into it yet, and also still don’t have much time to get into it. Of course, you will also have to modify the cgi code. Well, pretty much, you will need to mod something in every file to make that work. It’s not an easy first timer’s modification…
      ~jeremy

    86. Jeremy Dill Says:

      Dave,

      Good question. I believe it would be possible to do what you are suggesting. It would require some mods to make each form have unique prefix before each element name and also have it each form submit to a unique iframe. Further mods would have to be done to the js in order to use the prefix in the modification of the form elements. Ideally, I should rebuild this as a class and make it a plugin for xajax .5. That would make it easier to create separate instances.

      -Jeremy

    87. Dave B Says:

      Jeremy, a concept I am exploring is to write a function to return $frmOut, that will take the various parameters that I need, and then either embed them into the $frmOut form as hidden input fields, or add them to a global JS array of configs, one for each form placed on the page.

      Then, what I need to do is get some of that information to the fileAction() function via xajax_uploadHandler() so that I know what to do with the incoming file. I’m thinking that the query string might be the place to do that, by adding what I need to document.forms[’file_upload’].action string in the JS postIt() function.

      And, as you said, the iframes will need unique IDs etc.

    88. Jeremy Dill Says:

      Dave B,

      Sounds like a plan. Sorry its not already implemented. I would be interested in seeing your solution. Instead of playing with the querystring (which goes to cgi), you might want to just add a param to the xajax call to uploadHandler. You can use a js var set in your config or however and have that get passed as the second param to fileAction (maybe even use the same formPrefix var.. Then you just need to handle it in your fileAction with a switch or logic block.

      Jeremy

    89. Hello Says:

      I have downloaded you script .. its simply fantastic.. But i am facing a problem. that when i click on the send button the it says Uploading initiated. then preparing uploading but then it gives the error Upload Failed to begin.Your browser may not support this feature.

      i have checked the cgi_bin it is in correct path. and when i set $cgiDebug=1 then it gives the internal server error.
      The server encountered an internal error or misconfiguration and was unable to complete your request.
      plz reply asap

    90. Jeremy Dill Says:

      “Hello”,

      Please see my comment above to dilip dated 22 April 2007, 8:06 pm. It should help with your issue.

      - Jeremy

    91. Toifel Says:

      Hi Jeremy,

      first of all thanks for your Script, it looks quite fine.
      I just tried to install ist but after checking all debug-help here, i could not find help for the problem i have.
      The Server llway delivers a 500-Eror (Internal Server error), at the error-lg it says: “Premature end of script headers: upload.cgi”
      I really hop someone could give me a hint how to fix it because i would be very happy to gat a nice XAJAX-Uploadscript working.
      My Server is running on a Suse 10.1, php5.2.3

      Thanks,
      Toifel

    92. Jeremy Dill Says:

      Toifel,

      Hrm, that is a new one. Are you sure you can run other cgi scripts presently? This is a perl script. Here is more info about your error.

      http://htmlfixit.com/cgi-tutes/tutorial_Common_Web_dev_error_messages_and_what_they_mean.php#premature

      I reviewed the upload.cgi and didn’t see any clear issues with the code. Perhaps you can try the “use CGI::Carp qw(fatalsToBrowser);” command in the upload.cgi to give us more info about the problem.

      Thanks,

      Jeremy

    93. Toifel Says:

      Hi Jeremy,

      I’m soory for waising you time.. After some work i found out that a misconfiguration of the server invoked an error on the cgi-parser. So now at least the cgi works.
      Im going on trying to get the whole script running…

      Toifel

    94. Jon Says:

      I’m trying to incorporate additional image processing (such as resizing) into the fileAction. I’m not getting any errors but the re-processed images are not saved and moved to disk, just fileArr is. I suspect that I might be renaming and moving incorrectly. Or perhaps the order in which I’m adding the additional processing is incorrect. If I use $fileArr and end up with $img after reprocessing, what should the renaming and moving code look like? Any other suggestions or basic examples you can provide? Thanks very much.

    95. Tino Says:

      The script works perfectly. Great work.

      One little question; Is there a way to use other form fields as well? (Let’s say you want to upload a photo, and have an element for the title or something.)

    96. Jeremy Dill Says:

      Tino… that has been requested. I have plans to build that in at some point, but it is not yet available. Thanks. Jeremy

    97. Eddy Yanto Says:

      Looking great but hopefully there’s workaround for pure php xajax upload.

      Just notice a typo (duplicated feature list) within this page:
      5. Max File Size Restriction. And ALL other settings do not need to be configured by modifying the CGI script. Everything is easily configured via PHP.

      9. Max File Size Restriction. And ALL other settings do not need to be configured by modifying the CGI script. Everything is easily configured via PHP.

      Cheers,

      Eddy

    98. Tino Says:

      Thanks Jeremy.

      I had to make one small change to the javascript code of the function makeIFrame to make the upload form work with ‘cgiDebug=0′;

      I changed: if (d_nested) throwaway_node = document.forms[’file_upload’].removeChild(d_nested);
      To: if (d_nested) throwaway_node = (d_nested.parentNode).removeChild(d_nested);

      With the original code, the upload worked with cgiDebug set to ‘1′, but not with cgiDebug set to ‘0′.

      Tino

    99. Jon Says:

      Jeremy -

      Just wondering if your lack of response to my July 18 question is intentional or just an oversight?

      Thanks.

    100. Jeremy Dill Says:

      Jon,

      I guess i did overlook your comment. I am not sure exactly how to answer your question…but fileArr is just a pointer to the files that get uploaded. It contains size and name of the temp file, and the path to the temp file. I recommend using the rename command as it is shown in the example to put the files in some other location, and then do your modifications to them however you need. Read up on php file handling. http://www.softwareprojects.org/php-files-15.htm , http://www.phpnoise.com/tutorials/20/1 .

      Post your code and maybe I can help further.
      Jeremy

    101. Jeremy Dill Says:

      Eddy,

      Thanks for pointing out the issue on the page. Also, there will be a way to do pure php solution in newer versions of PHP. Post 5.2. I want to make this a full fledged xajax plugin and ideally have the option to use that hookin…thereby avoiding the cgi completely. Been really busy lately..

      Thanks,

      Jeremy

    102. Jeremy Dill Says:

      Tino… is this maybe because you changed your form name? Actually, thats a good idea…to make it relative rather than pointing directly to the form by id. thx…jeremy

    103. Marco Saba Says:

      Hi,

      Are you planning an OO version of the tool. Now it is really hard to integrate into my own xajax application.

    104. Jeremy Dill Says:

      Marco.. yes absolutely. I see the need for this. It will likely come by way of an xajax plugin. I need to do more research to determine the most logical method for an oo implementation. Maybe I can get to it this month. Thank you for your question.

      Jeremy

    105. Tellos Says:

      Hi there Jeremy,

      I trying to use ur aplication but for some reason it isnt working at all.

      Im running wamp to test it localy.

      xajax 0.5.0

      When I try to upload a file I get:

      Streaming c157ba1891453c0642951bda961f2cae_postdata

      Upload Failed to begin.Your browser may not support this feature.

      * MPP - Julho.pdf -uploading

      And with debug on:

      MAX Upload:2097152 bytes
      TMP DIR:c:/wamp/tmp
      SID:c157ba1891453c0642951bda961f2cae
      Speed Delay In Seconds:0.0993546648998352
      File:MPP%20-%20Julho.pdf

      Any idea of what may be causing this?

    106. Jeremy Dill Says:

      Tellos,

      I haven’t personally tried running my script on wamp. What ver of PHP is it? Also, are you seeing any files at all appearing in the temp folder? Most likely something wrong with the CGI’s ability to access the temp folder.

      Thanks,

      Jeremy

    107. Huy Says:

      Hi Jeremy,

      What a nice script you have! I’ve been trying to set it up in my server.

      I’ve got an another troubleshooting enquiry for you, unfortunately.

      My server is Apache , PHP Version 4.3.2.

      When I uploaded a file I saw “Upload Initiated” then a red box with “Streaming 2baa83caf76bce2ad40a7428093383eb_postdata” then Preparing Upload and 5 dots. After that I saw “Upload Failed to begin.Your browser may not support this feature.”

      I could see the iframe , it says :

      “MAX Upload:5242880 bytes
      TMP DIR:/var/www/brandmanagerbiz/temp
      SID:2baa83caf76bce2ad40a7428093383eb
      Speed Delay In Seconds:0.0993546648998364
      File:au_naid.gif”

      so I guess the CGI script was found and executed

      in the upoad_config_inc.php I changed $tmpDirInCGI to 1 and set the path in the CGI script. When I called the CGI in the browser it appeared to be fine (a blank page)

      The uploadDir folder permission was set to 777

      Do you know what causes this problem?

      Thanks

    108. Tellos Says:

      Hi there Jeremy,

      PHP version is 5.2.3 and yes theres 4 files when I try to upload something.

      Is there any other way to debug?

      Thanks in advance

    109. Jeremy Dill Says:

      Both Tellos and Huy.. Looks like you are both having close to the same issue.

      First, read the troubleshooting section at the very top of this page that talks about the files that are created. Look for

      “Please explain how the files in the temp folder are used.”

      Now, if you are seeing the 4 files appearing in then PHP and CGI aren’t having any problems with write access to the temp files. So, the most common problem can be eliminated. Here are a couple questions for both of you:

      1) Can you tell me if you are seeing any javascript errors with your javascript console? Try installing firebug in firefox (see my troubleshooting steps at top). Examine the XMLHTTP Repsonses from the server and see if there are any php Warnings or errors.

      2) Looking the temp files that have been made, what can you tell me about them. Is the _postdata file equal in size to the file you are trying to upload? Are you seeing any _err files?

      3) What settings are you using in your upload_config_inc.php? When trying to set this up for the first time, please use my original example files.

      4) try changing the startDelay to something greater than “1000000″..for example, try 5 million…and see what that does.

      5) if you want, if you have this avail to be reached remotely, you can send me an email with your url and i’ll test.

      Regards,

      Jeremy

    110. Huy Says:

      Hi Jeremy,

      Thanks for your response. Here are my comments.

      1) There were no errors reported by Firebug. I also turned on debug function in xajax, this is the output:

      Tue Aug 07 2007 09:03:40 GMT+1000 (AUS Eastern Standard Time)post: xajax=uploadHandler&xajaxr=1186441420562&xajaxargs[]=3ec26ffeee7d261d7d380be339966aa0&xajaxargs[]=4
      Tue Aug 07 2007 09:03:40 GMT+1000 (AUS Eastern Standard Time)Initializing Request Object..
      Tue Aug 07 2007 09:03:40 GMT+1000 (AUS Eastern Standard Time)Starting xajax…
      Tue Aug 07 2007 09:03:40 GMT+1000 (AUS Eastern Standard Time)Received [status: 200, size: 349 bytes]: Preparing Upload….Streaming 3ec26ffeee7d261d7d380be339966aa0_postdatablockwarninggetProgress();

      Please note “databloackwarninggetProgress();” , it may be something you’re looking for?

      2)There were 5 files in total in each upload, 1 random file with the exact same size as the file I was trying to upload
      The _postdata file is slightly larger in size than the one intended to be uploaded.

      I tried two upload the same file 3 times and got 15 files : 3 _flength files were the same size , 3 _qstring files were the same size and 3 _signal files were the same size. Yet the _postdata were all different to each other (2 bytes difference) and none of them were equal the one I uploaded. The other 3 random files were the same size as the original.

      I didn’t see any _err file.

      3) I kept much of the original settings from the zip package from this site.

      I only changed 3 places in the upload_config_inc file :
      $tmpDirInCGI from 0 to 1 but I also set the tempDir in the CGI script
      $uploadDir was changed but I guess the script uses the uploadDir in the CGI script (they are the same in both files btw)
      $xajaxRoot was changed but this variable was never used

      4) I changed the startDelay time to 5 million but it didn’t work

      5) Let’s see how we go.

      Thanks

      Huy

    111. Jeremy Dill Says:

      Huy.

      It looks like your issue may be with the fileaction function. If, as you explain, you are getting all of the files including the random name file..then cgi upload worked exactly as it should. The rest is handled by fileaction function located in the uplad_config_inc. Most likey, you are getting some sort of error when that executes and it is killing the completion of the script. Try changing this


      rename($fileArr['tmp_name'][$x],"/var/www/uploadtest/".$fileArr['name'][$x]);

      to use a folder where you want the final file to go.

      Please read the comments for this function and modify the function to do whatever it is you want to do with the uploaded file. The random name is kept until your fileaction script renames it.

      It occurs to me that my documentation doesn’t explain that…sry.

      - Jeremy

    112. Huy Says:

      Thanks Jeremy,

      I forgot mentioning that I already changed that line to the one I wanted :P from the post of Newbie. But it makes sense that something had killed the script before it finished

      I’ll test it some more and let you know

      Huy

    113. Marco Saba Says:

      Is it also possible to create a callback function on the file uploadhandler?
      So you can do some action on the uploaded file? for example display an image automatically after the upload…

    114. Jeremy Dill Says:

      function fileAction in the xajax_config_inc is essential designed for that purpose. After the file is uploaded, fileAction executes with $fileArr as the parameter. See comments on what $fileArr is in the config file.

      Basically, you can modify that however you want to do whatever you want with the files, and then run whatever code you in the function too. Then, fileAction returns $resp. $resp currently just supports script to execute on the clientside and a msg to update the status message div. (for example at end of fileAction…see this.

      
      $resp['msg']="Upload has completed.";
      $resp['script']="alert('Upload has completed.')";
      return $resp;
      

      But you could modify uploadHandler if you want to do something else with the returned data…

    115. iSlayter Says:

      Hello, Jeremy!

      Here is uploaded example: http://forexaw.com/new/1/main_page_sample.php
      Here is perl script: http://forexaw.com/cgi-bin/upload.cgi

      my php.ini(hoster gives ability for users to use theit own php.in): http://forexaw.com/new/1/php.ini

      Upload.cgi starts so
      #!/usr/bin/perl -w
      $high_max_upload = 524288000; # THIS WILL OVERRIDE PARAMETER PASSED TO SCRIPT IF VALUE IS LOWER
      $default_speed=10; # THIS IS DEFAULT SPEED IF NONE IS SET.
      $tmp_dir= “/home/httpd/vhosts/forexaw.com/httpdocs/new/1/”;# SET TEMP DIR MANUALLY IF YOU SET $tmpDirInCGI=1 IN THE PHP CONFIG FILE.

      use CGI;
      use Fcntl qw(:DEFAULT :flock);
      use File::Temp qw/ tempfile tempdir /;

      print “Content-type: text/html\n\n”;

      Anyway I’ve get error: Upload Failed to begin.Your browser may not support this feature.

      Why?! :’(

    116. Dmitry Says:

      http://moydodyr.info/up/main_page_sample.php

      I have a strange trouble…
      When i use Opera 9.22 ок Mozilla 2.0.0.2 - all ok - progreass bar go on and file upload correct.
      if i use Mozilla 1.5 or IE 6 - have next:

      Streaming 70635880e89a77288462a5ee252588a9_postdata
      ——————————————————————————–
      Preparing Upload.
      f1line.jpg -uploading

      and in debug iframe:

      MAX Upload:5242880 bytes
      TMP DIR:/home/moydodyr.info/uploadtmp/
      SID:70635880e89a77288462a5ee252588a9
      Speed Delay In Seconds:0.0993546648998364
      File:f1line.jpg

      No period (.) apear after “Preparing Upload.” and no error.
      In temp folder exists temp files but no files in result folder.

      I cant understand it - can you help me?
      PS: sorry for my eng

    117. Huy Says:

      Hi Jeremy,

      I’ve got something in the way so I haven’t been able to test it again. Thanks for your support , I’ll be in touch if there’s any problem

    118. Charbel Says:

      Hi Jeremy,

      I love this script, although i’m having issues with it, i’m getting the msg that “My browser does not support this feature”. I can see the Stream####, so I know my temp dir is fine and i’ve also made the IFrame visible at the bottom, but all that is coming back is the actual code in the cgi script, does that mean that my CGI script is not executing, its in the cgi-bin folder and i have the permissions set to 755 for the cgi file. you can test my script here:

      www.evolution.tv/main_page_sample.php

      I’m currently running on PHP V4. and i’m using xajax 2.4 along with the source code for that version.

      Perhaps that will give you an idea or a solution to my problem. Any help would be appreciated

    119. Charbel Says:

      Hi Jeremy,

      I solved the situation with the CGI file, my wemasters did not have it enabled. I’m getting the correct information in the IFRAME about the file, but i’m still getting “My browser does not support this feature”, and at the end of the upload I get an alert that says “Encountered error: Unable to open numfile: No such file or directory, Also unable to write to error file.” The file is not being uploaded also. Any Ideas to why this is happening and how I can fix this problem to get it working?

      Thank You,

      Charbel

    120. Jeremy Dill Says:

      Sorry everyone…been quite busy.

      iSlayter, if I click on your http://forexaw.com/new/1/main_page_sample.php it appears that you don’t have xajax installed properly. See my tip in TROUBLESHOOTING INSTALLATION about how to see if ajax call is working or not.

      Dmitry. I just used IE6 to upload a file no problem to your demo. Just a wild guess, I wonder if you should try limiting the speed a bit more if you are trying to upload to a local server. Perhaps IE6 cant handle the speed of maximum total throughput.

      Charbel, that error comes from the cgi script..basically, cgi script can’t write to the temp folder that you specified in $uploadDir. So check permissions. 777 is good starting point, then further restrict until you have issue. Also, make sure you are setting $tmpDirInCGI=0; unless you have modified the cgi.

      Thanks everyone. Hope your troubles are few!

      - Jeremy

    121. Charbel Says:

      Hey Jeremy,

      I already have those settings set in my scripts, anything else I can change or try for it to start uploading, like does cgi have to have certian permissions, do the upload paths have to be set a certain way? Anything you can think of would be appreciated.

      Thank You,

      Charbel

    122. RecklessB Says:

      Hi,

      Nice work Jeremy. I looked at the MegaUpload script a couple of years ago and found the upload engine lacking. It requires file locking and it tries to handle the upload itself. Like the comment in the file states “why try to re-invent the wheel”. So I believe I discovered a much more elegant approach.

      http://www.webdice.org/uber_uploader/

      Why try to handle the upload when CGI.pm has been around about a decade and does it for you. Let CGI.pm stream the files into a directory and simply read the directory as it increases in size. Why mess around with file locking? Why mess around with all these temp files? Let CGI.pm do it. No fuss, no muss.

      You have done a fantastic job with the MU engine, so I would be very interested seeing you code up an app using the UU engine.

      Regards,

      RecklessB

    123. Jeremy Dill Says:

      Charbel,

      Tried your page right now and getting errors…xajax install issues.

      Anyway, in every case I have seen so far, the issue you are describing is 1 of 2 problems.

      1) Permissions: If your permissions on the uploadTmp folder are not 777, try changing them to 777…and if you are using acls or something like that, please check to make sure that whatever service account name is executing your cgi (usually your apache account) has permissions to read/write to that folder. This is linux right?

      2) Bad path for temp folder. If you have not edited the CGI file, then the path you enter in upload_config_inc.php should be getting passed to cgi via a javascript variable “uploadDir” stored as part of $jsOut. For example

      $uploadDir="/var/www//trydobe.com/files/uploadtmp/"; 

      Note the trailing “/”. Perhaps this tmp folder is not getting passed for some reason. Try manually setting the upload tmp path by editing the upload.cgi file line 58. If you do this, you must also set $tmpDirInCGI=1 in your upload_config_inc.php script.

      It might help for me to see you output from your CGI script in cgiDebug mode (set $cgiDebug=1).

      Thanks,
      Jeremy

    124. neter Says:

      Hello i got the folling errors whene i try to debug upload.cgi

      Tue Sep 04 21:05:35 2007] [error] [client 127.0.0.1] Premature end of script headers: upload.cgi, referer: http://localhost/banner/upload/main_page_sample.php
      [Tue Sep 04 21:05:35 2007] [error] [client 127.0.0.1] Bad name after privlibexp’ at C:/wamp/perl/lib/Config.pm line 1219., referer: http://localhost/banner/upload/main_page_sample.php
      [Tue Sep 04 21:05:35 2007] [error] [client 127.0.0.1] Compilation failed in require at C:/wamp/perl/lib/Errno.pm line 8., referer: http://localhost/banner/upload/main_page_sample.php
      [Tue Sep 04 21:05:35 2007] [error] [client 127.0.0.1] BEGIN failed–compilation aborted at C:/wamp/perl/lib/Errno.pm line 8., referer: http://localhost/banner/upload/main_page_sample.php
      [Tue Sep 04 21:05:35 2007] [error] [client 127.0.0.1] Compilation failed in require at C:/wamp/perl/lib/File/Temp.pm line 132., referer: http://localhost/banner/upload/main_page_sample.php
      [Tue Sep 04 21:05:35 2007] [error] [client 127.0.0.1] BEGIN failed–compilation aborted at C:/wamp/perl/lib/File/Temp.pm line 132., referer: http://localhost/banner/upload/main_page_sample.php
      [Tue Sep 04 21:05:35 2007] [error] [client 127.0.0.1] Compilation failed in require at C:/wamp/Apache2/cgi-bin/upload.cgi line 62., referer: http://localhost/banner/upload/main_page_sample.php
      [Tue Sep 04 21:05:35 2007] [error] [client 127.0.0.1] BEGIN failed–compilation aborted at C:/wamp/Apache2/cgi-bin/upload.cgi line 62., referer: http://localhost/banner/upload/main_page_sample.php

      Plealse, help me find the problem

    125. Jeremy Dill Says:

      neter,

      Your errors indicate that you have issues with your cgi installation. Search this page for my comments to on July 15th, 2007 at 11:22 am to Toifel. Perhaps that will help.

      - Jeremy

    126. Jeremy Dill Says:

      Reckless,

      Indeed, I can see the advantages of your upload method vs the bulky old mega-upload cgi. Luckily, most of my effort is in the the client side and in the xajax code. It certainly would be fun to try your script as the handler. I am also at some point going to look into how well PHP v 5.2 handles an upload natively.

      Does your code have any kind of speed control?

      Cheers!

      - Jeremy

    127. RecklessB Says:

      Hi Jeremy,

      No, as the upload is handled by CGI.pm the upload speed cannot be throttled. I had one user who was using the MU engine on a heavy traffic site. He switched over the the UU engine and after several months and noticed the UU engine was much more reliable. Here is a link to the thread.

      http://sourceforge.net/forum/message.php?msg_id=3613903

      It does not surprise me as CGI.pm has been around for about 10 years and the code has been reviewed by countless developers. UU is really just a fancy wrapper around the CGI.pm upload functionality. Also, I am not convinced throttling the upload speed is a good thing.

      Regards

    128. RecklessB Says:

      I have heard some bad things about the new PHP functionality. Maybe after a couple of more releases. Sorry cannot remember the links where developers were griping about it. Anyway, as most of the people who download UU have no control over what version of PHP or extra modules are installed on their server I cannot go down this route even if I wanted to. However, it would be sweet to have a pure PHP solution.

    129. Newbie Says:

      RecklessB,
      You can try a pure PHP solution here : http://www.scbr.com/docs/products/dhtmlxVault/index.shtml
      This code uses doesn’t require any kind of third-party script on your server but I think that using AJAX or JS to handle upload maybe an insecure way to do so.
      BTW, this code costs you $99 for a progress bar. So will you pay for it :) ?

    130. RecklessB Says:

      Very nice file selection interface. Probably the best I have seen so far. Very smooth. However, maybe I’m missing something but I do not see a ‘real’ progress bar. So, I cannot comment on a pure PHP solution until I see a working progress bar. Also it comes in 4 flavors, one of which is a perl version. The perl version uses the MU upload engine with the tesUpload config file. I could not find any credit to either project in the source code or text documents. :( I don’t use any MU code but even I credit the author for inspiring Uber-Uploader.

      http://sourceforge.net/projects/tesupload/
      http://sourceforge.net/projects/megaupload/

    131. RecklessB Says:

      If you are going to shell out any money for an uploader, filechucker is a much better value. I’ve seen the source code of earlier versions and it is a very professional job. Also, it looks like they give excellent support.

      http://encodable.com/filechucker/

    132. RecklessB Says:

      Sorry for all the posts but I just want to be clear. Uploading files has always been possible in PHP. However, it is not possible to send any output until the post has finished in PHP versions less than 5.x. Therefore, a progress bar is not possible because you don’t get back any info to build it while the file is uploading. So, a pure PHP uploader with a true progress bar is NOT possible with a PHP version less than 5.x.

    133. Newbie Says:

      Well, I tried Jeremy’s example ( 0.5 ) and after click the “Cancel” button, the upload progress stopped immediately but in my localhost ( I’m using XAMMP/Windows ), after clicking the “Cancel” button, then the upload progress is not stopped at all. Actually, it continues uploading in background to complete although I haven’t made any change in all of the files. Can you give me a suggestion please ? Maybe there is something special in Windows ?

    134. Aldo Says:

      HI:
      How do i get the content type of the file? The file array have name, size and tmp_name. Its possible to get the content_type??

    135. Jeremy Dill Says:

      Newbie,

      If you have cgidebug on… what do you see in the window after you cancel?

      Aldo,

      I am not sure..but can’t you use PHP to get the content type by looking at the temp file $fileArr[’tmp_name’].

      See this http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/.

      Thanks,

      Jeremy

    136. Newbie Says:

      After choosing the file and clicking the Send button, there was my debug :

      MAX Upload:16777216 bytes
      TMP DIR:c:/xampp/htdocs/
      SID:afa9631fc5af1db8aae462b0d3ca246b
      Speed Delay In Seconds:1.06525019637887

      And after 3 secs I clicked the Cancel button, then nothing happened ( but the progress bar was stopped ) but after a while, a text appeared :

      File:test.rtf

      I checked the upload folder and I saw that the upload had already completed ( but file was not renamed ) as the time the text “File:test.rtf” was shown.

      After all, I did another test. But after clicking the Send button, I opened the Windows Task Manager and killed the process “perl.exe” and clicked the Cancel button. Everything went normal as the example you showed me.

      I think that in the Windows environment, the script cannot close the Perl loader so that the upload progress still continues. Do you have any idea about this ?

    137. Jeremy Dill Says:

      Here is what happens when you cancel right now.

      1) a variable is set on the desktop, next time xajax does an update of the progress status, it checks that var (frameSet). If false, it will kill the php progress, and display a message…cancelled. It will also try to delete any of the files associated with the project.

      Question.. do you get the “Upload was Cancelled.” message?

      2) On return after cancel, essentially, the whole script starts over. The previous IFrame is supposed to get destroyed.

      
      d_nested = document.getElementById("destination"+frameAdv);
              if (d_nested) throwaway_node = document.forms['file_upload'].removeChild(d_nested);
       }

      This is where that happens… however, I just realized that the iframe isn’t destroyed when you are in cgidebug mode. The idea behind that was to leave the iframe behind so you can actually see the err message that comes when the perl script detects that the file was cancelled. It knows it is cancelled if it can no longer read th tmp post file. Weirdly, it seems to take a long time for the perl script to figure this out…so you might see the file posting from the browser for a bit longer…but evenutally you should get a message in the cgi box that says “Upload Cancelled”. However, pretty much right after you click Cancel, on the php side, you should see in the uploadtmp folder an _err file ….open it up and it should say. “Temp file was deleted. Upload was cancelled?”

      So.. are you getting any cancellation errors…anywhere?

      - Jeremy

    138. Newbie Says:

      The first time I click on the Cancel button, then the progress bar is stopped, but the upload is still in progress ( in background, of course ). After waiting for the upload to be completed, I click the Cancel button the second time, then the “Upload was Cancelled.” message will be displayed. But in the uploadtmp folder there is no _err file, only 4 files : _signal, _qstring, _postdata and another file. It makes me really confused now @_@.

    139. Jeremy Dill Says:

      Newbie…it does appear that your issue might be related to either your platform (windows) or permissions (somehow). When you press cancel… all 4 files are supposed to be deleted. this includes _signal, _qstring, _postdata and _flength. If these aren’t being deleted (by the php script line 43 of upload_xajax_inc), then cancellation will not happen on the perl side.

      So, the issue lies in php not being able to delete that file. I recommend looking for errors in your Response with FireBug after you press cancel… should be some clues there.

      -jeremy

    140. Raine Says:

      Hi Jeremy,

      Thanks for the fantastic script. Tried to install it on my server with debug on, I get this:
      Streaming c3646e3688b7bfa127d25180dcab63f1_postdata

      Upload Failed to begin.Your browser may not support this feature.

      The frame below it is blank, however.

      BTW, Im on apache 2 server with mod_cgi and mod_perl installed, and Im using your package for xajax .5

      Thank you so much.

    141. Jeremy Dill Says:

      Hi Raine, please the troubleshooting section in the article above. Specifically, see "If cgi is not executing…the following applies"

      Thanks,

      Jeremy

    142. Chris LS Says:

      Jeremy,

      This seems like a really great script. I’ve been trying to get it to work on my environment today with no luck. Here is what I am using:

      - Windows Xampp installation (PHP 5.2)
      - XAJAX 0.24

      I’ve read through all most of the form posts and the troubleshooting guide. It seems that I’m stuck where the poster “Huy” above got stuck. Currently, when I attempt to upload a file through the sample script (main_page_sample.php) the browser returns the “Upload Failed to begin.Your browser may not support this feature” error message. But when I look in my upload directory I see 5 files written there, but the function named fileAction never gets fired off ( I put some additional logging in there to confirm this). So the CGI is getting fired off and its submitting the form and writes the files to the upload folder, but the php script never seems to kick off and pick up and finish the job.

      I have been running FireBug and I can confirm that when the page loads I get a SID and there are several attempts to call the uploadHandler function. The response which gets fired back looks something like:

      I’ve changed the following configuration parameters in upload_config_inc.php:

      $uploadDir=”c:\\temp”;
      $tmpDirInCGI=1;
      $maxFiles=1;
      $refreshDelay=”500000″;
      $cgiDebug=1;

      So again, i have the temp files getting written to the right location, the other script just never does the final writing and clean up. It seems like its making it to the following code in upload_xajax_inc.php:

      } else { //NOT STARTED YET
      if ($recursionaddAssign(”loadtext”,”innerHTML”,”Preparing Upload.”.$dots);
      if ($cgiDebug){
      if(file_exists ($uploadDir)) $objResponse->addAssign(”okstatus”,”innerHTML”,”Streaming “.$sid.”_postdata” );
      else $objResponse->addAssign(”okstatus”,”innerHTML”,”PHP is not able to read the temp dir!! - (”.$uploadDir.”)”);
      $objResponse->addAssign(”okstatus”,”style.display”, “block”);
      $objResponse->addAssign(”okstatus”,”className”, “warning”);
      }
      $objResponse->addScript(”getProgress();”);

      Any direction you could provide to me would be a huge help as I am looking forward to being able to use this script.

    143. Jeremy Dill Says:

      I actually think there may be a bug in the cgi script..that it just doesnt run properly in an IIS server. Seems to lockup. I don’t have a solution at this time, but I know everyone working on linux doesn’t have such issues. Sorry, I know thats not a solution. If you want to get into debugging the cgi on windows, let me know how it goes. Jeremy

    144. Jorge Mario Says:

      I had made all the needed configurations an steeps to work ok with the script but now it shows me this error message in a javascript alert messeage: Encountered error: Unable to open numfile: No such file or directory. Also unable to write to error file , could you tell me whait it means, and thank’s a lot for this beutifull work, really thank u!! hope for your answer……

    145. Jeremy Dill Says:

      Hi Jorge,

      Sounds like permissions issue on the temp folder. Also, if you are trying to do this in windows…I can’t promise that it will work. Other people have had issues with the CGI not executing properly.

      cheers

      jeremy

    146. Metric Says:

      Hey Jeremy,

      I seem to be having a issue with the uploader.

      First question: Where does the cgi script look for tmp directories relations? Does it look based on the cgi, php or the root directory for the site?

      Second question: I know it probably is the tmp folder, however I do have it to set to 777, the cgi script seems to see it and processes the upload and says complete. Nevertheless, when it calles fileAction, $fileArr is empty and the debug on the cgi does not output a file name or puts any files in the tmp directory.

    147. Metric Says:

      Hey Jeremy,

      I am having certain issues with the script:

      1. It sees the cgi and can access the tmp dir, however it doesn’t write any tmp files to the directory and in fileAction $fileArr is not filled in.
      - I have a feeling before fileAction can be called it is removing the files before it can process it. This is with the the newest xajax. I know xajax is functioning properly as it is getting the sid and my own xajax scripts are functioning.

      2. You really should declare your variables.

      3. If this is anything I am using php 4.3.9 currently, planning to get it upgraded but just have to beat the server admin in the head a few. ;D

    148. Jeremy Dill Says:

      Metric,

      Make sure you are using the matching version of xajax…so use the v5 if you are using v5. I don’t declare Variables for PHP…does anyone? Why would you? That is one of the nicest things about php. To init a var, you just start using it. But you may be having a problem if you are having Notices turned on in your PHP config. Turn off notices. You should really only have to worry about Errors and Warnings. Notices can break your xajax return (see the console of firebug with XHTTP Request logging option enabled).

      Finally, I just noticed all my demos were broken because I moved my directory structure around. They are all fixed now. The key is to consider your paths…and consider permissions as carefully as possible. Your script must have read /execute all the way down the directory tree to access anything in a subdirectory. 90% of the issues people have reported are permission related.

      Thanks!

      jeremy

    149. Klaus Says:

      Hi Jeremy,

      thanks a lot for this nice piece of software.

      I’m using a windows 2000 system with the lateste apache, php, perl, xajax … I’m using your sample page to upload files. Everything works fine until the file(s) have been uploaded to the upload directory. However, there is no progress on the progress bar, no download completed and not fileAction executed. Is there anything I’m missing?

      It seems that none of the functions in the upload_xajax_inc.php are executed (getSID and uploadHandler).
      In your sample page this file has been include with require(’./upload_xajax_inc.php’); It resides in the same directory as the sample page.

      I would appreciate every hint.

      Have a nice day,
      Klaus

      P.S.
      Many of the comments found on this page where of great help. Thanks to everyone who contributed

    150. Alexander Franksmann Says:

      Hello Hello,

      i am trying to use the upload script for serveral hours but I have no success till now.

      After I am able to use cgi scripts the following error occurs:

      “Encountered error: Session was not defined.”

      It seems that the CGI installation of my webserver can not access the Server Vars.

      If have no idea anymore what to do.

      It would be nice if anyone has a advice for me.

      Thanks.

      Alexander

    151. Jeremy Dill Says:

      Hi Klaus, It seems that a lot of people have tried and failed to get this script working in a windows environment. I will post a warning about that in the article itself. I am sorry for the time wasted. If you solve it, please let us know.

      - Jeremy

    152. Jeremy Dill Says:

      Hi Alexander, please provide more information about your platform…what are you running this on?

      thanks,

      Jeremy

    153. Spencer Pan Says:

      My english is not good. I embed the script in my site, then test it with firefox3.0b5 in ubuntu8.04. It runs fine I can upload files but my WYSIWYG editor in same page doesn’t work any more. Seems the editor can’t get focus. And I try same page under windowsXP with IE6. The editor works but the uploader alway popup a new window. The file uploaded but the fileAction() function seems never run.

      But when I test the sample page,it’s no problem with both platform.

      I’m not good at ajax. I think maybe there is conflict between the script and my editor since they all have iframe?

    154. Jarrod Oberto Says:

      Hi Jeremy,

      Don’t know if you can help me, but I got your progress bar to work locally (works great, thanks) but when I uploaded it to another server (paid hosting) I now get an Apache error “Method Not Allowed” (in bold) with “The requested method POST is not allowed for the URL /1/upload.cgi.” below it.

      I guess this is a server issue, but do you know if this is easy to rectify. I do not have access to the server config (obviously)

      Thanks

      Jarrod

    155. Jarrod Oberto Says:

      Hi Jeremy,

      I have run into a little problem with you uploader. I have got it working successfully on my local server but when I move it to an external server I get the following error in the CGI iframe:

      “Method Not Allowed” in bold
      under that says “The requested method POST is not allowed for the URL /1/upload.cgi.”

      Now I have no idea what this means. It is likely a server issue but after posting with my host they tell my the CGI file can be anywhere. The hosting is Linux/Apache. If you could give me a hint as to where to look or what this mean I would much appreciate it.

      Regards

      Jarrod

    156. TheYOSH Says:

      Hi,

      why are you using a CGI?!?!? Xajax is a PHP framework. And why the hell use a cgi script for uploading. PHP can do the same…..
      To bad. I liked the idea of a Xajax fileupload plugin. But now…. sorry mate.. no go for me. Can’t use cgi.

    157. Jeremy Dill Says:

      Spencer Pan & others. I confess that my code is not very good with compatibility, and in general, it is not very well written overall. You might notice that I actually made this script years ago, so I am trying to phase it out and replace it with something new at some point. I am going to close the comments here because I think that I have answered just about every possible question as it pertains to my code specifically. Just search the page for your errors, and see what I have written. Make sure you cgi environment works before banging your head against my utility. We all have mishaps from time to time that we have to hash out. Sometimes it’s a lonely world out there. Good luck.

      On a brighter note, I am absolutely AMAZED to see how many people are interested in this. According to my stats, over 3000 people have downloaded the code. Apparently, their is a big need for a real Xajax plugin that can both support native php upload functions (available as of 5.16) or perhaps the uber solution as well. TheYOSH is right that cgi is yucky, but at the time I wrote this, there weren’t many options. Look it up, you will find that before php 5.1.6 there is no native way to get file stats during upload. Perhaps that is why so many people are settling for my pathetic, mediocre solution. It does work, but it’s not a lot of fun to implement.

      Thank you all for contributing.

      Jeremy