0

This is a basic image upload script, that when a user uploads a file it should move it to his folder that is created when he registers, then it inserts the location of the photo into a database. It will run on an apache mysql set up I have on my computer but then I uploaded it to my host and it does not seem to work?

class Photo extends Session {
function profile_photo($img) {
    $this->start_session();
    $uid = $_SESSION['userid'];

    $tmpname = $_FILES['image']['tmp_name'];
    $randname = rand(1, 1000000);
    $type = preg_match('/.tmp/', $tmpname);


        move_uploaded_file($tmpname, "user/$uid/$randname.jpg");
        $sql = "INSERT INTO user_images (image_url, user_id) VALUES ('user/$uid/$randname.jpg', '$uid')";
        $q = mysql_query($sql);
        header("Location: home.php");

}
}

File Permessions are 777

It is inserting into the database just the move_uploaded_file function does not seam to be moving the uploaded file?

Aaron
  • 11,239
  • 18
  • 58
  • 73
  • 2
    Please elaborate on what isn't working and what you've done to debug it. Making people guess is not going to get you very good answers. – Wesley Murch May 01 '11 at 12:23
  • 1
    Dibs on folder permission answers! – JohnP May 01 '11 at 12:23
  • 1
    Matt... you failed to ASK A QUESTION.... Get in there and edit it quick, before it gets deleted as cyber trash. – corlettk May 01 '11 at 12:24
  • How are you so sure that file `$randname.jpg` does not already exist? – Marcel Korpel May 01 '11 at 12:25
  • Re your update: You need to describe what happens. What errors do you get? What do you see? – Pekka May 01 '11 at 12:27
  • @Pekka go to voikai.com in your address bar and register it's still very buggy but then you'll see photo upload form.. it'll just give a blank page, type /home.php after to get to the main site as you will see it's still in the experimental stage. – Aaron May 01 '11 at 12:30
  • Do you have error reporting turned on? See http://stackoverflow.com/questions/1824282/php-production-server-turn-on-error-messages – Pekka May 01 '11 at 12:33

1 Answers1

1

Check if the folder where you want to store the file is writeable on your local pc.

Tommy
  • 1,277
  • 1
  • 11
  • 22