Results 1 to 3 of 3

Thread: PHP Copy Command Works with one glitch

  1. #1
    Join Date
    Jul 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default PHP Copy Command Works with one glitch

    Hi All,

    I am using the PHP Copy call function to copy an existing file in a folder and rename it for the new page that is being created and it works to get the additional file created inside the folder, but then when I try to go to that file by way of direct url it gives a NO SUCH FILE OR DIRECTORY error.

    Here is what I did to explain so someone can tell me where I went wrong:

    1. I created a PHP file that has the Copy function to generate the desired file and that works fine and generates the file inside the newly created folder to hold it...

    PHP Code:
    $listing_name str_replace(" ","_",$listing_title);
        
         
    $targetFile "webpage/site_webpage.php";
         
    $targetCopy="webpage/$listing_name.php";
        
         
    copy($targetFile$targetCopy);
        
         if (
    file_exists($targetCopy)) {
         
    $destination "webpage/$listing_name.php";
     } else {
         echo 
    "Failure: $targetCopy does not exist";
     } 
    2. There is some code above that to get the $listing_name (title) to name the file, but all this works and that file is named site_detail_create_page.php and when ran generates the desired file and places it in the WEBPAGE folder that is in the main public_html directory with the site_detail_create_page.php file

    3. But when I try to open that file through the web using www.mydomainname.com/webpage/$listing_name.php (whatever name assigned for file as is dynamic) it generates the NO SUCH FILE OR DIRECTORY error..

    Does anyone know if I missed something like needing to declare that new folder of WEBPAGE somewhere so the server knows it exists, etc..?

    Thanks in advance,
    JD

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes. You probably also need clearstatcache() which is specifically mentioned for use with file_exists() and a number of other stat functions:

    http://php.net/manual/en/function.clearstatcache.php

    before you check if the file you just created exists.

    You should be able to use it without parameters:

    Code:
    $listing_name = str_replace(" ","_",$listing_title); 
         
         $targetFile = "webpage/site_webpage.php"; 
         $targetCopy="webpage/$listing_name.php"; 
         
         copy($targetFile, $targetCopy); 
         clearstatcache();
         if (file_exists($targetCopy)) { 
         $destination = "webpage/$listing_name.php"; 
     } else { 
         echo "Failure: $targetCopy does not exist"; 
     }
    But also should be able to specify the specific file. I'm not sure if it makes any difference. Read the man page to decide what might be best and experiment to see what works.



    There could also be other problems.
    Last edited by jscheuer1; 02-26-2015 at 03:16 AM. Reason: detail
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I would also like to add that at the point where you check if the file exists, try checking with a full and absolute server path - something like;
    Code:
    if (file_exists('/home/www/mydomain.com/'.$targetCopy)) {
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Similar Threads

  1. IE Glitch
    By ianglen in forum Other
    Replies: 1
    Last Post: 02-19-2013, 05:29 PM
  2. Resolved Firefox Glitch
    By Webiter in forum Other
    Replies: 2
    Last Post: 01-19-2012, 09:32 PM
  3. Help with table glitch
    By zchrykng in forum HTML
    Replies: 0
    Last Post: 07-16-2011, 05:43 PM
  4. loadXML only works with Alert() command included ... CRAZY!?
    By satelliteCoder in forum JavaScript
    Replies: 0
    Last Post: 11-02-2009, 06:51 PM
  5. AOL glitch
    By vkbarefoot in forum Flash
    Replies: 4
    Last Post: 08-23-2007, 12:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •