Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Variable to function problem

    I'm coding an image website that allows users to upload images, no problem with uploading images. What I am having trouble with is, when a user signs up, I create a specfic folder for that member, this is where there images will go.

    The code below is the function, I've obviouslly taken out the ftp login stuff. The function main duty is to change the folder permissions of the members specfic folder, however I am having trouble grabbing the excat members folder.

    PHP Code:
    <?php
    function modechanger ($mod,$folder) {
    $host ''
    $user ''
    $password ''


    $conn ftp_connect("$host");

    if (!
    $conn)
    {

    echo 
    'Error: Could not connect to ftp server';

    exit;
    }


    $result ftp_login($conn$user$password);

    if (!
    $result)
    {

    echo 
    "Error: Could not log on as $user";

    ftp_quit($conn);

    exit;
    }

    if (
    ftp_site($conn'CHMOD '.$mod.' '.$folder)) {

    return 
    "true";
    }

    else {

    return 
    "false";

    ftp_quit($conn);

    exit;
    }
    ftp_close($conn);
    }
    Below is code that communicates with above function.

    PHP Code:
    $folder '../content/$uname/'
       
    modechanger("0777" "$folder"); 

    I keep getting this msg

    "Warning: ftp_site() [function.ftp-site]: ../content/$uname/: No such file or directory in /hsphere/local/home/scotsman/ladyfame.com/stuff/images.php on line 31"

    The path to folder is correct and I need to move out of folder and back, then into the content folder. But for some reason the $folder variable isn't passing across with the information. The $uname is set with the members name, this is done through a hidden field in the upload image form.

    any help would be greatly appreciated.


  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    few steps:
    - echo $folder to see if $uname is expanded( replace ' with " if not)
    - check $uname to see if have the value you expect
    - of course check if directory exists and the path is correct.

    regards

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Yes, the variables inside double quoted strings will only get parsed by php.
    Code:
    $folder = '../content/$uname/';
    should be
    PHP Code:
    $folder "../content/$uname/"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah it appears yous are correct regarding the use off " and '.

    For some reason the script still isn't working, I'm beginning to think I'll just upload all images to one folder and not bother with member specfic folders. I only looking at doing member folders, as I didn't want to have a clash of excat two image names being uploaded. Think I'll just run a duplicate check on the mysql database side first and make sure there no clashes before uploading, proably be easier.

    I've posted full code below, maybe someone here can figure it out. Be handy to know a solution to this if possible but its not essential now.

    PHP Code:
    function modechanger ($mod,$username) {
    $host 'hidden this'
    $user 'hidden this'
    $password 'hidden this';
    $folder "../content/$username/"


    $conn ftp_connect("$host");

    if (!
    $conn)
    {

    echo 
    'Error: Could not connect to ftp server';

    exit;
    }


    $result ftp_login($conn$user$password);

    if (!
    $result)
    {

    echo 
    "Error: Could not log on as $user";

    ftp_quit($conn);

    exit;
    }

    if (
    ftp_site($conn'CHMOD '.$mod.' '.$folder)) {

    return 
    "true";
    }

    else {

    return 
    "false";

    ftp_quit($conn);

    exit;
    }
    ftp_close($conn);
    }

       
    session_start();
       include(
    "hidden this");
       switch (@
    $_GET['do'])
       {
       case 
    "updimage":
       
    $uname $_POST['aname'];
       
    modechanger("0777" "$uname");
       
    $destination1 "../content/$uname"."/".$_FILES['pix1']['name'];
       
    $temp_file1 $_FILES['pix1']['tmp_name'];
       
    move_uploaded_file($temp_file1,$destination1);
       
    $filepath "/images/$uname"."/".$_FILES['pix1']['name'];
       
    modechanger("0755" ,"$uname");
       
    $itit $_POST['itDesc'];
       
    $lfsect $_POST['asect'];
       
    $lfcategory $_POST['cat'];
       
    $cid date('hisdmy');
       
    $today date("Y-m-d");
       
    $stat "waiting";
       
    $connection mysql_connect($host,$user,$password)
                 or die (
    "Couldn't connect to server.");
       
    $db mysql_select_db($database,$connection)
                 or die (
    "Couldn't select database.");
       
    $sql "INSERT INTO lfimages (imageid,loginName,category,section,title,imagepath,createDate,status)
                VALUES ('$cid','$uname','$lfcategory','$lfsect','$itit','$filepath','$today','$stat')"
    ;
       
    mysql_query($sql);
       
    $mess "image was succesfully uploaded.";
       
    header("Location: ../panel-images.php?uname=$uname&ltype=$lfsect&message=$mess");
      break; 
      
      } 
    I did insert an "echo "$folder"; line underneath where $folder is set within the function. It returned the folder path twice, like ../content/Ladyfame/../content/Ladyfame/.

    Ladyfame is the correct members name, no idea why im seeing it twice. I'm also not seeing any error messages, script processes completely (until i put echo folder in). Information is going to the database and the correct path is listed, however the filename isn't attaching to the end of the $filepath variable.

    as i said, its not essential to get a soultion to this but would be handy to know one.

    Last edited by Shaun1978; 01-26-2009 at 06:23 AM.


  •  

    Posting Permissions

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