Problem uploading files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pezholio
    New Member
    • Jun 2007
    • 22

    Problem uploading files

    Hi,

    It seems that every time I put together a new script to upload a file I always have problems, here's the latest one:

    I've got a form with two file input fields, when I submit the form, everything goes OK, but the files don't upload, the permissions on the folders are fine and dandy (Both 777). Here's my code:

    [PHP]if(is_uploaded_ file($_FILES['image']['tmp_name'])){

    $target_path = "/home/default/ratemyplace.org .uk/user/htdocs/newsite/images/premimages/";

    $target_path = $target_path . basename( $_FILES['image']['name']);

    $ext = substr($_FILES['image']['name'], strrpos($_FILES['image']['name'], '.') + 1);
    $ext = strtoupper($ext );

    if ($ext != "JPG"|"JPEG"|"G IF"|"PNG") {
    $errorarray[] = "<li><a href='#image'>S orry, you can only upload images in .jpg, .gif or .png format</a> $ext</li>";
    $error ++;
    } else {

    if(move_uploade d_file($_FILES['image']['tmp_name'], $target_path)) {
    $image = basename( $_FILES['image']['name']);
    } else{
    $errorarray[] = "<li><a href='#image'>T here was an error uploading your image, please try again</a></li>";
    $error ++;
    }
    }

    }

    if(is_uploaded_ file($_FILES['report']['tmp_name'])){

    $target_path = "/home/default/ratemyplace.org .uk/user/htdocs/newsite/uploads/";

    $target_path = $target_path . basename( $_FILES['report']['name']);

    $ext = substr($_FILES['report']['name'], strrpos($_FILES['report']['name'], '.') + 1);
    $ext = strtoupper($ext );

    if ($ext != "PDF"|"DOC" ) {
    $errorarray[] = "<li><a href='#report'> Sorry, you can only upload reports in .pdf or .doc format</a></li>";
    $error ++;
    } else {

    if(move_uploade d_file($_FILES['report']['tmp_name'], $target_path)) {
    $report = basename( $_FILES['report']['name']);
    } else{
    $errorarray[] = "<li><a href='#report'> There was an error uploading your report, please try again</a></li>";
    $error ++;
    }
    }

    }
    [/PHP]

    Any ideas?

    Cheers
  • nashruddin
    New Member
    • Jun 2008
    • 25

    #2
    Have you add enctype to your form? it looks like this:

    Code:
    <form enctype="multipart/form-data" action="somefile.php" method="post">

    Comment

    Working...