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 12 of 12
  1. #1
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts

    php upload problem

    PHP Code:
            $uploaddir 'http://www.websiteurl.com/';
            
    $uploadfile $uploaddir $_FILES['userfile']['name'];
            
            if (
    move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
               print 
    "File is valid, and was successfully uploaded. ";
            } else {
               print 
    "Error uploading file!";
               exit;
            }
            
            
    $url $_FILES['userfile']['name'];
            
            
    mysql_query("INSERT INTO pics (URL) VALUES ('$url')") or die("Error inserting picture!<br><br>".mysql_error());
            echo 
    'Picture has been added!'
    it dies... why doesnt it work?

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    did you suppy an enctype in your form ?
    <form name="bella" method="POST" action="?" enctype="multipart/form-data"> etc ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yeah, still giving an error

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    DOH , should have spotted this the first time (but the form thing is the usual reason)
    $uploaddir = 'http://www.websiteurl.com/';

    you can't copy to a URL use the filepath instead ..

    $uploaddir='/home/user/uploads/';

    and of course make sure the directory has the correct permisions
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by firepages
    DOH , should have spotted this the first time (but the form thing is the usual reason)
    $uploaddir = 'http://www.websiteurl.com/';

    you can't copy to a URL use the filepath instead ..

    $uploaddir='/home/user/uploads/';

    and of course make sure the directory has the correct permisions
    how do i know what the filepath is?
    i want to upload to the main directory

  • #6
    New Coder
    Join Date
    Mar 2004
    Posts
    39
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it si not very wise to upleoad into the main directory, so i reccomend just making a folder called "upload" so your $uploaddirectory will be "/upload"
    If there is any LAWN BOWLERS that are under 16 here PM me!

  • #7
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    but where do i get all the var/www stuff from

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    if you are on a unix machine then chances are the root directory path is

    /home/$your_account_name/public_html/

    but you can probably use

    $_SERVER['DOCUMENT_ROOT'].'/uploads/';

    simply <?echo $_SERVER['DOCUMENT_ROOT'];?> if you want to know what the path is , in the case of PHP as a CGI you may need another variable.
    PHP Code:
    <?
    echo'<pre>';
    print_r($_SERVER);
    echo
    '</pre>';
    ?>
    to see them all !
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thank you vry much i will try this

  • #10
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    /home/********/public_html/uploads/Error uploading file!

    I added in

    echo $uploaddir;

    after the line that defines it:

    $uploaddir = $_SERVER['DOCUMENT_ROOT'].'/uploads/';

    I've also CHMODded the folder to 777 and I was trying to upload a file called barcode.gif

    any help?

  • #11
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    Hi add ,
    PHP Code:
    <?echo '_FILES array = <pre>';print_r($_FILES['userfile']);echo '</pre>';?>
    to see what the contents of $_FILES['usefile'] actually contains , it will contain an error message if one exists , if its empty , check your form !
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #12
    Regular Coder
    Join Date
    Jul 2003
    Location
    New Zealand
    Posts
    435
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for that little peice of code, ive left that in the script as debugging information. its working now, turns out i had put enctype="multipart/form-data" in the wrong tag

    thanks


  •  

    Posting Permissions

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