Form Upload In PHP, Why Cant I Upload CSV?

Discussion in 'PHP' started by timallard, May 11, 2009.

  1. #1
    Hey guys...

    I'm trying to upload a CSV file via form. Im trying to limit my filetypes to only CSV...but it is not letting me upload..

    I can do it fine with jpeg/gif etc but not csv.. any ideas?

    check out my code please:


    $types = array('image/jpeg', 'text/csv');

    $target_path = "data/uploads/";
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

    if (in_array($_FILES['uploadedfile']['type'], $types)) {
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    $success = "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded successfully.";
    } else{
    $error = "<img src=\"../images/error-1.png\">" . " There was an error uploading the file, please try again!";
    }
    } else {
    $error = "<img src=\"../images/error-1.png\">" . " You can only upload a CSV file! " . "<strong><a href=\"update.php\">Try Again</a></strong>";
    }

    echo "Upload: " . $_FILES["uploadedfile"]["name"] . "<br />";
    echo "Type: " . $_FILES["uploadedfile"]["type"] . "<br />";
    echo "Size: " . ($_FILES["uploadedfile"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["uploadedfile"]["tmp_name"];


    When i upload a photo, all my echos work fine, and it moves the file to my server. When i try to upload a CSV it does not move the file and gives me my error.

    Any ideas?


    Thanks,
    -Tim
     
    timallard, May 11, 2009 IP
  2. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #2
    I just added 'text/comma-separated-values' as part of the array and it successfully uploaded the file.

    BUT it was a brand new CSV I made in excel.

    It will still not upload the CSV that I want... Is it a specific csv type i need to allow? im so confused... ugh.
     
    timallard, May 11, 2009 IP
  3. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #3
    SOLVED.

    File size issue on my form page. I removed it and now works like a charm.. -blushy face-
     
    timallard, May 11, 2009 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    They are often coded as plain text "text/plain" and not "text/comma-separated-values". Not sure if that's a problem, but if it isn't from excel it may have a different content type.
     
    jestep, May 11, 2009 IP
  5. fourfingers

    fourfingers Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    also, make sure you're saving it as a csv now xls out of excel ... different worlds
     
    fourfingers, May 13, 2009 IP