Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by LLLLLLL

  1. I'm wondering the best way to handle validation messages for blind people, or sight-impaired.


    In my application, the situation on a save with errors is:

    1. User clicks save
    2. AJAX call goes to save the record; wait bar appears on the page's status bar
    3. Error is returned. The wait bar changes to show "Error on save"
    4. Below the status bar, each field name is listed with the appropriate error message. ("Name - Cannot be blank" or whatever)
    5. Within the fields themselves, the same message is shown again. (Next to the "Name" label on the page, "cannot be blank" would show up.)

    This functionality is great for sighted people. But for non-sighted, I'm not sure exactly how to handle it. Should an error become "selected" or something? I mean, it's just a div. I don't really have the answer.


    I posted this in general HTML but it could frankly be AJAX or JS or something. I think HTML is probably the most correct.

  2. (As usual, this is a different type of question; if it's in the wrong forum please move it.)


    I own two domains: example.com and example.ru. These sites are essentially mirrors of each other but they provide better geo-awareness than having only one site.


    If I have files that I need to copy from example.com to example.ru on a semi-regular basis, how do I do this programmatically? Obviously I have the login credentials, nameservers, IP addresses, and whatever else of both servers. What's the code to accomplish this? I have not ever tried to send files from one server to another. It certainly would be better than FTPing the files down to a local machine and then FTPing back up to the other server.



  3. This forum is "programming theory" so I assume this is the most appropriate place to put this. (Admins or someone feel free to move this if the location is incorrect.)


    The issue is that a site, example.com, loads slowly to international users because of its US-based host. So the thought is to buy...





    ... and host those domains on servers near the respective location. Or something like this.


    So the question is... what's the best way to handle users getting to the right site from the right location? There are google results out there that sort of address this question, but I'm wondering what has worked for others, or what you've heard of working.


    I think the solution will be to install a package on my server that can tell where the user is from, and to either redirect the user outright or to let them click a link to go to a more "local" version of the website. 


    Thoughts? Have you handled this? Howso?



  4. So in the code above, there's a user-configured option $download_attempts_allowed. This person had it set to 1, and most people set it to 2.  Because each Android request to download is two calls:

    1) One call is made (now that's one attempt)

    2) Another call is made  (now the attempt is too many, so it wants to return to the other page; everything is confused which is why the new header request probably overrides the first one or something).


    So by changing this person's configuration to allow two calls, the second call works. It's a hack. What I'll have to do for real is to disallow an attempt when there's already one file downloading, or to check the timestamp on when it started. But for right now I can change this person's attempts allowed to 2 and there's no issue. 


    On iOS it appears to be similar, but no one has yet to determine if there's a good way to download mp3s onto iOS, because Apple wants people to use iTunes only. Some people have issues with mp3s on Apple, others don't. I'm not sure what the answer is there but it's not for this forum.

  5. Well done, SocialCloud, what you've posted there definitely is the answer on Android. I am having someone else verify iOS right now. Basically the fix is to bump up the number of retry attempts that the user has configured. (It was 1; should change to 2.) Seems like a hack...


    But as expected, it's not a code issue. Thanks for finding that. I'll mark something solved as soon as I know about iOS.

  6. https://code.google.com/p/android/issues/detail?id=1978


    As stated about half way down, it is an intended part of the android system. It has nothing to do with not working on one server. Not sure why you are not experiencing it on another server, but it is intended. You will have to rewrite your code to comply with android.

    I don't think this has anything to do with the current topic.

  7. It was not my intention to keep the code from you. I have been away all day. But saying it's a coding issue when the code clearly works on all other sites and browsers, but not on this site only with mobile, seems completely illogical. Here's the modified/simplified code. Almost all of it is application-specific and won't help you, but here it is anyway.

    if ( !common::gx( 'guid' ) ) {
    	echo translated_text::find( "Download.NoFileGuid" );
    $guid = common::g( 'guid' );
    // get the file location from preferences
    { phpfreaks...  read some preferences from DB }
    $source_dir        = 
    $root_download_dir = 
    $enforce_ip        = 
    $retry_mins        = 
    $download_attempts_allowed = 
    $data = { php freaks... read info about file }
    // these error numbers come from download_product constants
    if ( $data === false ) {
    	exit_w_msg( "error=681" );
    // read the product
    $dp = new download_product();
    $dp->read( $data );
    // need the order guid and the customer name.
    $data = { php freaks ... get customer name and order name }
    $order_guid = 
    $oid        = 
    $cname      = 
    //  php freaks... this is where the log shows we reach this code twice
    //	common::debug_to_log( $dp );
    //	common::debug_to_log( $download_attempts_allowed );
    // check status
    if ( $dp->status >= $download_attempts_allowed ) {
    	exit_w_msg( "id=$order_guid&error=" . download_product::ERR_ALREADY );
    // if an attempt has already been made on the file, verify the download rules
    if ( !empty( $dp->attempt_time ) ) {	
    	if ( $enforce_ip && $_SERVER[ 'REMOTE_ADDR' ] != $dp->ip_address ) {
    		exit_w_msg( "id=$order_guid&error=" . download_product::ERR_WRONG_IP );
    // find the source file to copy. we copy to a temporary directory
    // for safety; it's apparently better to stream from a directory that
    // doesn't actually exist except for temporarily. plus we may
    // alter the file before we stream it.
    $source_file = $source_dir . $dp->filename;
    if ( !file_exists( $source_file ) ) {
    	exit_w_msg( "id=$order_guid&error=" . download_product::ERR_NO_SOURCE );
    // find out where we need to copy the files.
    if ( !file_exists( $root_download_dir ) ) {
    	exit_w_msg( "id=$order_guid&error=" . download_product::ERR_NO_DIR );
    // the guid folder should NOT already exist. it should be deleted from
    // a previous download attempt. but if it DOES exist, just go ahead and
    // use it.
    if ( !file_exists( $root_download_dir . $guid ) ) {
    	// now create the new directory where we will copy the file
    	$dir_made = mkdir( $root_download_dir . $guid );
    	if ( !$dir_made ) {
    		exit_w_msg( "id=$order_guid&error=" . download_product::ERR_DIR_CREATE );
    // so create the filename, and then copy the file.
    $filename = $root_download_dir . $guid . "/" . $dp->filename;
    // that last line isn't always right. if the dp filename is
    // a subfolder/filename, remove the subfolder.
    if ( strpos( $dp->filename, "/" ) !== false ) {	
    	$just_filename = basename( $source_file );
    	$filename = $root_download_dir . $guid . "/" . $just_filename;
    $copy_ok = copy( $source_file, $filename );
    if ( !$copy_ok ) {
    	exit_w_msg( "id=$order_guid&error=" . download_product::ERR_FILE_COPY );
    // check for existence. would be odd, wouldn't it?
    if ( !file_exists( $filename ) ) {
    	exit_w_msg( "id=$order_guid&error=" . download_product::ERR_NO_FILE );
    ////////////////////////////////// all of the below is up for debate
    //header( "Pragma: public" ); // required
    //header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    //header("Cache-Control: private",false); // required for certain browsers 
    header( "Content-Description: File Transfer" );
    header('Content-Transfer-Encoding: binary'); // test
    header('Expires: 0'); // test
    header('Cache-Control: must-revalidate'); // test
    header('Pragma: public'); // test
    header( "Content-Type: application/octet-stream"); // test
    header( "Content-Type: application/octet-stream" );  // commented. test
    header( "Content-Length: " . filesize( $filename ) );
    header( 'Content-Disposition: attachment; filename="' . $dp->download_filename . '"' );
    ob_clean(); // test
    flush(); // test
    readfile( $filename );
    ///////////////////////////////////// all of this is up for debate. ^^^^^^^^^^
    // we're done streaming. do some cleanup.
    unlink( $filename );
    $rm_dir_ok = rmdir( $root_download_dir . $guid );
    // now update the download status:
    $dp->status = $dp->status + 1;
    $dp->ip_address = $_SERVER[ 'REMOTE_ADDR' ];
    $d = date( 'Y-m-d H:i:s' );
    if ( empty( $dp->attempt_time ) )
    	$dp->attempt_time = $d;
    // this function logs ALL attempts (ip, time) on a file. security.
    $dp->log_attempt( $_SERVER[ 'REMOTE_ADDR' ], $d, $guid );
    function exit_w_msg( $msg ) {
    	header( "Location:download.php?" . $msg );
  8. I'm not "redirecting all over the place", and I never use HTTP_REFERER. I do appreciate the help but what you're suggesting here is not correct.

    1) There's a GET parameter passed that references a database row

    2) That row knows the file, knows if it was downloaded before, knows other security settings related to the download

    3) That file gets sent to the browser

    4) All logic to redirect (in #2) goes through a single function that calls header() and then calls exit.


    Posting the whole file isn't something that will help because the issue only occurs on one server. There's too much application logic on there anyway. Maybe I can send it to you privately, but at this point I'm awaiting the web host.


    I should have probably posted this in the Apache forum or something. The web host is unable to get back to me with the reason for the multiple requests on the file.

  9. I found that the script is getting called twice, and this is the problem. Because after the file is downloaded once, it's not allowed to be downloaded again. The script checks for this and if the download limit was reached, it redirects to the original page with a GET paramter so the appropriate error is displayed. The HTML that gets returned has the message "No more download attempts are allowed", which is the valid code in that situation. But why the script gets called twice is beyond me. 


    I have the server people looking at the logs to get this information. I've long suspected some htaccess or Apache or other rewrite that somehow makes the URL request or response get screwed up. That's probably the case for the code getting hit twice, but it's odd to me that the HTML would be returned as an attachment; the normal behavior is just to be directed to the page (the page that's made up of the HTML that's being returned).


    Output buffering is 4096, for what it's worth. 


    I'm awaiting information from the server people.

  10. There's no problem with $filename, because again, this works from a desktop browser. I have already examined the variables with logging and of course they are correct, since it's the exact same code from desktop or mobile browser.


    I've tried changing to octet-stream and I've tried dozens of other variations. This may be useful, but it doesn't change the fact that this code works on other servers. It looks like octet-stream is a better choice, and I'll do that, but again, this code works on other servers to the same device and browser.

  11. I will try that, but why would those files download...

    1) Successfully from a desktop browser

    2) Successfully from my server on a mobile browser (instead of using the customer's site)

    3) Unsuccessfully from his server and mobile.




    #2 makes it seem like it's a server thing. The same code runs on my dev server as the customer's server. The same files download for me without issue.

  12. I've written software that lets a file get downloaded by a user click. There is one customer site where downloads are failing but only on Android browser (and possibly other mobile?). Both mp3s and PDFs fail to download, and both file types stop downloading at about 14.61 KB. To clarify, what that means is that my Android phone shows that the mp3 was downloaded, with a file size of 14.61, even though the actual file is 3MB or so.


    The code is pretty standard stuff:

    header( "Content-Description: File Transfer" );
    header( "Content-Type: application/force-download");
    header( "Content-Length: " . filesize( $filename ) );
    header( 'Content-Disposition: attachment; filename="' . $dp->download_filename . '"' );
    readfile( $filename );

    Since this code works on hundreds of sites, and since there's no mobile issue on other sites, a code issue seems unlikely. I think there might be a server-side issue but I don't know what to check. Download issues are often php.ini limits on file size, but since this same file downloads on desktop browsers without issue, a php.ini issue seems unlikely.


    Any ideas on why this would fail on mobile?


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.