#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    101
    Rep Power
    10

    Question "Can't find file or folder"


    Is the error message I get when I try to delete a file from a folder

    What I am doing is "uploading" files to a folder and wanting to then delete both files, each from different folders. They're images, one hi-res the other lo-res

    I used the echo statement to see what files the function was trying to delete, it turns out that it is trying to delete files that have the same name, even though they don't have the same name

    Where am I going wrong?
    This is the partial code to delete files
    PHP Code:
    public function Delete($id)     { 
            try{             
    $_id this->db->connection->real_escape_string($id);  
    $file_hi $this->GetFileName($_id);              
    $file_lo $this->GetFileName($_id);  
    echo(
    "Image name is: " $file_hi."<br/>".$file_lo);             
     die(); 
    It does include the echo statement for troubleshooting

    This one is the partial code for the function that is called inside the Delete function
    PHP Code:
    private function GetFileName($id)     { 
            try{              
    $query "SELECT imagehi, imagelo FROM tbl WHERE id=" $id;              
    $result $this->db->connection->query($query);              if(!$result){    
                  throw new 
    Exception($query);    
              } else {        
                 return 
    $row['imagehi'];   
                 return 
    $row['imagelo']; 
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,185
    Rep Power
    9398
    Originally Posted by cssbonding
    it is trying to delete files that have the same name, even though they don't have the same name
    You have to admit that sentence is a bit... contradictory.

    Anyways,
    PHP Code:
    return $row['imagehi'];
    return 
    $row['imagelo']; 
    A function cannot return two different values at once - only the first return matters. Now that value could be an array containing whatever you want, but it's still the one array. You can also have more than one return statement, but when any one of them gets executed the function stops.

    How about adding a discriminator to GetFileName() indicating whether to return the imagehi or imagelo? If you think that GetFileName() will often be used to grab both values then make the discriminator optional in which case the function returns an array with both values.
    Last edited by requinix; December 6th, 2012 at 12:27 PM. Reason: "is"
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    On planet earth
    Posts
    101
    Rep Power
    10
    Thanks for that, but have tried all discriminators AND, OR, XOR etc, but it seems that neither one of them are working
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,185
    Rep Power
    9398
    What? Those are boolean/bitwise operators. I'm talking about a "discriminator" as in
    A characteristic that enables things, people, or classes to be distinguished from one another.
    As in a second parameter to the function and depending on the value of that parameter you return the imagehi, the imagelo, or both.

    Comments on this post

    • cssbonding agrees : genius

IMN logo majestic logo threadwatch logo seochat tools logo