treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Question about image admin panel

  • Hi,
    i followed a tutorial on how to create a image gallery with a admin panel, and when i tried to upload a image, it gave me this error:

    Warning: move_uploaded_file(C:/webroot/gallery/images/gallery/c1b55bfadb00c4304fb9f774eefafb93.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampplite\htdocs\php\cms\library\functions.php on line 21

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampplite\tmp\php22F.tmp' to 'C:/webroot/gallery/images/gallery/c1b55bfadb00c4304fb9f774eefafb93.png' in C:\xampplite\htdocs\php\cms\library\functions.php on line 21
    Error uploading file

    line 21 on functions.php is part of a function to upload the images:
    function uploadImage($inputName, $uploadDir)
    {
    $image = $_FILES[$inputName];
    $imagePath = '';
    $thumbnailPath = '';

    if (trim($image['tmp_name']) != '') {
    $ext = substr(strrchr($image['name'], \".\"), 1);

    $imagePath = md5(rand() * time()) . \".$ext\";
    $result = move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath);

    if ($result) {
    $thumbnailPath = md5(rand() * time()) . \".$ext\";
    $result = createThumbnail($uploadDir . $imagePath, $uploadDir . 'thumbnail/' . $thumbnailPath, THUMBNAIL_WIDTH);

    if (!$result) {
    unlink($uploadDir . $imagePath);
    $imagePath = $thumbnailPath = '';
    } else {
    $thumbnailPath = $result;
    }
    } else {

    $imagePath = $thumbnailPath = '';
    }

    }



    Can someone please explain what is going on?

    thanks,
    James
  • make sure that the upload directory /images/gallery/ is writable