Announcement

Collapse
No announcement yet.

php file_exists and parse error

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

    php file_exists and parse error

    I am trying to use some php (SellerDeck 2016) to check if a file exists on the server

    We manage the site content from an import feed that does not have images so we plan to load images manually to a folder and name them using the product reference and the section name

    Then ask the code to check if they exist, if they do display them and if not we will either leave blank or add a default image.

    But first I need to get the php working.
    I have tried various adaptations of the code and always seem to get an error
    "Parse error: parse error in main on line #"
    Tried it with absolute, relative and full URLs
    Also with single and double quotes round the image variable

    Code:
    <actinic:block php="true" >
    $manufimage = "http://www.sellerdeck-upgrade.truska.co.uk/acatalog/manuf-logos/<actinic:variable name="SectionName" />.png"  encoding="perl" />" ;
    	echo $manufimage ;
    	if (file_exists($manufimage)) 
    		{
    			echo "File Exists" ;
    		}
    		else
    		{
    			echo "File Does NOT Exist" ;
    		}
    </actinic:block>
    As you can see at the moment, to keep it simple, I am just looking for a result to the if statement - the image display should not be an issue.

    Must be something simple here that I am missing.

    Thank you in advance....
    David Cunningham

    www.truska.com
    -----------------------------
    ECommerce (SellerDeck) & Web Design, Hosting, Search Engine Optimisation, Social Media and Remote Backup (Truska Backup)

    #2
    It looks to me as if this can't work because

    1. Your use of double quotes throughout the filename content is breaking the variable text early.

    2. You appear to have mixed up the placement of the .png in the filename content so the actinic variable encoding is appearing after it.

    Mike
    -----------------------------------------

    First Tackle - Fly Fishing and Game Angling

    -----------------------------------------

    Comment


      #3
      PS. This isn't the way I'd do it anyway.

      As the sellerdeck php code runs on the PC rather than the server you're better off if you store your images locally on the PC and let sellerdeck upload them onto the server. This will be MUCH faster and more efficient.
      -----------------------------------------

      First Tackle - Fly Fishing and Game Angling

      -----------------------------------------

      Comment


        #4
        You need to follow some rules when getting SD Variables into PHP strings:
        Code:
        $manufimage = "http://www.sellerdeck-upgrade.truska.co.uk/acatalog/manuf-logos/<actinic:variable name="SectionName" />.png"  encoding="perl" />" ;
        Needs to be:
        Code:
        $manufimage = 'http://www.sellerdeck-upgrade.truska.co.uk/acatalog/manuf-logos/<actinic:variable name="SectionName" encoding="perl" selectable="false"/>.png';
        P.S. There's probably a Variable for the http://www.sellerdeck-upgrade.truska.co.uk/acatalog/ bit so you could make the code site independent.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Code:
          $manufimage = '<actinic:variable name="CatalogURL" encoding="perl" selectable="false" />manuf-logos/<actinic:variable name="SectionName" encoding="perl" selectable="false" />.png';
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            P.S. And Mike's suggestion about keeping the images within (say) a manuf-logos folder within your Site folder is a good one.
            Code:
            $manufimage = 'manuf-logos/<actinic:variable name="SectionName" encoding="perl" selectable="false" />.png';
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Thanks Mike

              re the method of doing it
              The site is updated several times week from a csv using Replace
              There are NO images within or linked with the csv so we are planning on gradually building a image bank and using the product ref and section names as the file names as they are in the csv and thus in database.
              This will require some more php to check for illegal characters and caps etc with "to be" file-names, the next step once this first bot is working.

              That is why we need the file_exists as a majority of products will actually never have an image and SellerDeck has no way of knowing.

              You comments re quotes were spot on - I have tried it with numerous configurations but was just not careful enough seemingly.

              The Parse error has no gone - big step forward - Thank You....

              But the file_exists call does not seem to be working yet.

              It always returns a negative - but if I actually display the image in the "does not exist" else area it DOES display thus proving it exists - and using the same $file-name variable for the src and for the file_exist call.

              Therefore
              Got the Parse Errot sorted
              But not got the if (file_exists(filepath/name) to work

              This is the correct code nwo partially working per above....

              Code:
              <actinic:block php="true" >
              $manufimage = "http://www.sellerdeck-upgrade.truska.co.uk/manuf-logos/<actinic:variable name="SectionName" />.png" ;
              	if (file_exists($manufimage)) 
              	{
              		echo "<img src='" . $manufimage . "' alt='<actinic:variable name="SectionName" />' title='<actinic:variable name="SectionName" />' align='right' />" ;
              	}
              	else
              	{
              		echo "<img src='" . $manufimage . "' alt='<actinic:variable name="SectionName" />' title='<actinic:variable name="SectionName" />'  ;
              	}	
              </actinic:block>
              David Cunningham

              www.truska.com
              -----------------------------
              ECommerce (SellerDeck) & Web Design, Hosting, Search Engine Optimisation, Social Media and Remote Backup (Truska Backup)

              Comment


                #8
                Hi David,

                My point about the way to do it is more about where you store the images.

                If you put them on the web server then sellerdeck has to look for the image on the server via http and will then download them into the cache / internal browser so you can preview the page on the desktop. This happens in the background while sellerdeck is running but it's obviously going to be much slower and less efficient to do this from the server than from the local disk.

                You can still use the same methodology. Just do it from somewhere on the local disk.

                Mike
                -----------------------------------------

                First Tackle - Fly Fishing and Game Angling

                -----------------------------------------

                Comment


                  #9
                  PS. I'm not sure file_exists works for remote servers. It's much better all round to store your images locally on the PC
                  -----------------------------------------

                  First Tackle - Fly Fishing and Game Angling

                  -----------------------------------------

                  Comment


                    #10
                    Thanks Norman

                    I saw your comments on previous post re Perl encoding and selectable but was puzzled on how to set that but I have worked that out now and all is set as you suggest, as far as I can tell.
                    But the if statement is still just returning negative every time.

                    I have moved the folders back into the acatalog folder again - That is manageable - eventually there could be 12,000 images in here? But I doubt it will get that far, at least not for a long time.

                    To upload the images SellerDeck needs to know they exist and as as they are not directly referenced from anywhere in the database it can not know unless they are listed in Additional Files (am I correct here) - and this is a non-started in this scenario -

                    We could run a routine to add an extra col with an an image name to the csv to add the image name on import but in 90% of the cases, at least to start with, it would not exist and thus report as an error - or we would need to edit the code that compiles the site to stop it making that check.

                    The code I now have, incorporating your comments is:

                    Code:
                    <actinic:block php="true" >
                    $productimage = "<actinic:variable name="CatalogURL" encoding="perl" selectable="false" />product-logos/<actinic:variable name="ProductReference" />.jpg";
                    			
                    		if (file_exists($productimage)) 
                    			{
                    				echo "File Exists" ;
                    				echo "<img src='acatalog/product-logos/no-image.jpg' alt='<actinic:variable name="ProductName" />' title='<actinic:variable name="ProductName" />'  width='80' />" ;
                    			}
                    			else
                    			{
                    				echo "<img src='" . $productimage . "' alt='<actinic:variable name="ProductName" />' title='<actinic:variable name="ProductName" />' width='80' />" ;
                    				echo "<br>File Does NOT Exist<br>" ;
                    			}	
                    	</actinic:block>
                    But the if statement as mentioned is still not working.

                    Yes I know the actions are the wrong way round (no-image in the true etc) - as it always is false I have the image displaying there in the meantime so I can see it and prove it does exist.

                    It is loaded to my dev server at
                    http://sellerdeck-upgrade.truska.co.uk/index.html
                    so it can be seen - albeit till I make more attempts to change it.

                    [PS - I have this running for both section or manufacturer images and product images - using same code with minor amendments hence the change in variables names and paths above from the previous posts]

                    Again Thanks for comments
                    David Cunningham

                    www.truska.com
                    -----------------------------
                    ECommerce (SellerDeck) & Web Design, Hosting, Search Engine Optimisation, Social Media and Remote Backup (Truska Backup)

                    Comment


                      #11
                      See my comments above about file exists and remote servers. It's better to test for the file on the local system.
                      -----------------------------------------

                      First Tackle - Fly Fishing and Game Angling

                      -----------------------------------------

                      Comment


                        #12
                        Please listen to expert advice!

                        1) If you generate a valid IMG tag within SellerDeck, then SD will detect it and upload the image for you. E.g. generate <img src="manuf-logos/myimage.png" /> and the job is done. Relative paths will be sorted out and the image uploaded to acatalog as usual.

                        2) PHP that uses SellerDeck variable as strings needs to be single quoted and include encoding="perl" selectable="false". Double quotes may lead to problems in the future. See my post #6.
                        Norman - www.drillpine.biz
                        Edinburgh, U K / Bitez, Turkey

                        Comment

                        Working...
                        X