SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: fopen problems

  1. #1
    SitePoint Member natalalaa's Avatar
    Join Date
    May 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face fopen problems

    Hi,

    I'm having problems with fopen()

    I'm getting the warning on my screen:

    Warning: fopen(/hostingSlowRep/admin/support/uploads/2260_Berlin - pictures from Janine 022.JPG): failed to open stream: No such file or directory in \\Snap429640\captprimary\hostingSlowRep\admin\support\controllers\progress_cntl.inc.php on line 132


    My code:

    $uploaddir = '/hostingSlowRep/admin/support/uploads/';
    $ulpoadfile = $uploaddir . $fname;
    fopen($ulpoadfile, 'r');

    I can see the correct file in: \hostingSlowRep\admin\support\uploads but for some reason it doesn't work.

    I'm pretty sure there is a simple explanation for that.
    Can anyone help please?

    Cheers,
    Natalia

  2. #2
    SitePoint Zealot mwasif's Avatar
    Join Date
    Apr 2007
    Location
    Pakistan
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using relative path.

  3. #3
    SitePoint Member natalalaa's Avatar
    Join Date
    May 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried:

    $uploaddir = '/uploads/';

    and

    $uploaddir = '../uploads/';

    still the same error mesaage

  4. #4
    SitePoint Zealot mwasif's Avatar
    Join Date
    Apr 2007
    Location
    Pakistan
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Where is your .php file located and where is the upload folder?

  5. #5
    SitePoint Member natalalaa's Avatar
    Join Date
    May 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php file:

    \\Snap429640\captprimary\hostingSlowRep\admin\support\controllers\progress_cntl.inc.php

    the file to be opened:

    \\Snap429640\captprimary\hostingSlowRep\admin\support\uploads\2260_Berlin - pictures from Janine 022.JPG

  6. #6
    SitePoint Zealot mwasif's Avatar
    Join Date
    Apr 2007
    Location
    Pakistan
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your PHP script has permissions to read the file? Use is_readable() to know about this.

  7. #7
    SitePoint Zealot mwasif's Avatar
    Join Date
    Apr 2007
    Location
    Pakistan
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This .php file is an inlcude file, try using this path

    support/uploads/

  8. #8
    SitePoint Member natalalaa's Avatar
    Join Date
    May 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    but the warning message says failed to open stream: No such file or directory.

  9. #9
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its basically the equivalent of a 404, you need to check the link to the file... I don't understand the path you mentioned, are you working on a network?

    To avoid, you structure your file handling in a way that will show a user friendly error. for example:
    PHP Code:
    if (file_exists($path))
    {        
        if (
    $handle = @fopen($path'a'))
        { 
                    
            if (
    fwrite($handle$contents))
            {
                echo 
    'all good';
                        
            } else {
                    
                    echo 
    'Changes could not be saved';
            }
                    
        
    $handle fclose($handle);
                    
            } else {
             echo 
    'Could not open file';
            }
            
    } else {
        echo 
    'file does not exist';

    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  10. #10
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,227
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    fopen

    mwasif's suggestion didn't work? Maybe it's a problem with the spaces in the name? Or maybe try using the joliet name.

  11. #11
    SitePoint Member natalalaa's Avatar
    Join Date
    May 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried:

    support/uploads/

    and

    /support/uploads/

    Still nothing :/

  12. #12
    SitePoint Member natalalaa's Avatar
    Join Date
    May 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I think I solved my problem now, well sort of it doesn't give me an error any more, but it takes me to a blank page.

  13. #13
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check your error reporting level, probably you have generated a fatal error and it is not showing because error reporting is on level 0.
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  14. #14
    SitePoint Member natalalaa's Avatar
    Join Date
    May 2007
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My debug:

    if (file_exists($ulpoadfile))
    echo "file exists; ";
    if (fopen($ulpoadfile, 'r'))
    echo "works?!";

    I'm being taken to an empty farme with message:

    file exists; works?!

    What else can go wrong?
    PHP seems to think that the file is open, but actually it's not


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
  •