Announcement

Collapse
No announcement yet.

PHP fopen

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP fopen

    I have a small PHP script which outputs to a file using "fopen" and the "w" switch eg:

    $myFile = "1.html";
    $file = fopen($myFile, 'w') or die("cant open file");
    $stringData =" stuff here ";
    fwrite($file, $stringData);
    fclose($file);

    this sits at the bottom of the product layout and outputs some code to a file beautifully. All works well on the first upload pass.

    The "w" switch does not appear to be overwriting the existing file at the next upload.

    Any suggestions how or why the second upload will not generate new files?


    Bikster
    SellerDeck Designs and Responsive Themes

    #2
    Put the w in double quotes: "w"
    I don't know if this makes a difference, but every actual code example I've seen shows double quotes, and know the quote-type is important in php.

    Comment


      #3
      Cheers Alan.

      I think I have tracked it down to the BASEHREF I added between the first and second uploads .. I have <span> hidden the error outputting so the PHP must be having an issue with the BASEHREF code .... probably as this introduces unescaped quotes for the path ... I am going to use the full version opposed to the variable.


      Bikster
      SellerDeck Designs and Responsive Themes

      Comment


        #4
        When passing Actinic variables into PHP, I nearly always use:

        $xyzzy = '<actinic:variable name="Plugh" encoding="perl" selectable="false" />';

        Using single quotes around the variables and encoding="perl" selectable="false" within the variable instance deals with two quirks that might have messed us up.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Cheers Norman - I had the selectable added already - it was the basehref causing the issue so I changed to been in the un-compacted version and escaped the quotes and that resolved.

          Nice tip about the single quotes - will bear that in mind for the future.


          Bikster
          SellerDeck Designs and Responsive Themes

          Comment


            #6
            Round 2

            The PHP script is now working fine now everything is escaped. It takes some product details and outputs to a .html file.

            At the moment I have display:none at the bottom of the ProductLayout to generate the PHP file ... but this is far from ideal as Google may whack the page as the content is essentially there but just not displaying.

            Any suggestions on how to output the file (each product needs to be output) so that Actinic generates the file and uploads to the server without it showing on the main product page?


            Bikster
            SellerDeck Designs and Responsive Themes

            Comment


              #7
              Any suggestions on how to output the file (each product needs to be output) so that Actinic generates the file and uploads to the server without it showing on the main product page?
              Unless your PHP uses echo "...."; type statements it won't actually add anything to the generated pages's HTML so there's no need to hide anything. Take a look at your page source and see what's there.

              E.g.

              <actinic:block php="true">
              // write some files
              // crunch some numbers
              </actinic:block>

              Puts nothing on the page.
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #8
                P.S. Some good techniques that include file creation on http://community.actinic.com/showthread.php?t=31559 where posts 8 and 9 together automatically create a file for each product that is then displays instead of the usual search results.

                The main magic trick is that if you create a Layout Type of type Popup, then layouts within that can send their contents to a file rather than to the page. This is how Extended Info pages are built and we can subvert this capability for other useful things.

                The other trick in this post is that the code to invoke the file creation is added to the Product List Layout (where only 3 variations apply), rather than to the umpteen possible Product Layouts.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Originally posted by NormanRouxel View Post
                  Take a look at your page source and see what's there.
                  Jont == Donkey

                  I viewed the page source and did a search on the product name and it was found several times ... forgetting it is in the alt text and all other manner of Actinic gumph. Pillock.


                  Bikster
                  SellerDeck Designs and Responsive Themes

                  Comment


                    #10
                    I'm presuming you're the one on the right...
                    http://bit.ly/489PiT

                    Comment


                      #11
                      That's me on the right just on the way out for the night - the lippy is a git to apply neatly with cloven feet


                      Bikster
                      SellerDeck Designs and Responsive Themes

                      Comment


                        #12
                        I used a similar idea to benchmark a pages generation time.

                        http://community.actinic.com/showthr...ight=benchmark

                        Shows how to append data to a file on generation, useful for logging.

                        Comment

                        Working...
                        X