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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post

    File upload issue

    I have a script running in the public_html/admin directory and It is trying to upload to the public_html/documents directory I have the following code:


    PHP Code:

    $uploaddir
    ="../documents";
    $uploaddirurl "http://uvfmusic.com/xpress/documents";


    $resimadi $_FILES['userfile']['name'];
    $uploadfile ='"' $uploaddir.'/'$resimadi '"';


    $tags=$_POST['tags'];
    $description=$_POST['description'];
    $doc_title=$_POST['doc_title'];
    $instruments=$_POST['instrument'];
    $tempo=$_POST['tempo'];
    $genre=$_POST['genre'];
    $sounds=$_POST['sounds_like'];


    move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir);


    //$query = "INSERT INTO `files` (`id`,`file_name`,`file_path`,`tags`,`description`,`doc_name`,`genre`,`instrument`,`sounds_like`,`tempo`) VALUES(NULL,'$resimadi','$uploaddirurl','$tags','$description','$doc_title','$genre','$instruments','$sounds','$tempo')"; 
    //echo $query; 

    //mysql_query($query) or die(mysql_error());  
    echo "<center><br><h1><a href=\"$uploaddir/$resimadi\">$resimadi</a> File was uploaded</h1><br><br><a href=\"javascript:history.go(-1);\"><< Back </a></center>\n";


    It keeps throwing the following error:

    PHP Code:
    Warningmove_uploaded_file(../documents): failed to open streamIs a directory in /home/content/s/a/h/sahiaman/html/xpress/admin/doc_add.php on line 61

    Warning
    move_uploaded_file(): Unable to move '/tmp/php54FlTN' to '../documents' in /home/content/s/a/h/sahiaman/html/xpress/admin/doc_add.php on line 61 

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    The error message gives you a clue; you haven't used a closing slash, e.g. '../documents/' to indicate the path you want to move the file to. I would make sure you use the closing slash and you should consider using an absolute path (just in case PHP is attempting to move the file to /documents/ (under the '/' root path, one directory up from /tmp as indicated by ../documents/).


  •  

    Posting Permissions

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