file upload - weird!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Amy Kimber

    file upload - weird!

    Hello all,

    ok, I have a file upload secton to my site, two pages, one with a
    form and one that does the uploading.... some files upload fine, other
    don't

    an exe of 300k will upload, but a word document of 40k wont and so on,
    in the php.ini a limit of 2mb is set (I haven't changed it, it's how
    the file originally as, so it isn't my maths that's gone mad).

    The code was taken more or less from the php manual... any iedas
    people? Please? I'm going mad! And just when I was starting to enjoy
    PHP :-(

    Many thanks,

    Amy


    <?php

    session_start() ;


    $uploaddir = '/home/sites/site1/web/translation/';



    $uploadfile = $uploaddir . $_FILES['userfile']['name'];


    if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile))
    {

    $msg = "File (" . $_FILES['userfile']['name'] . ") is valid, and
    was successfully uploaded. ";
    //print_r($_FILES );
    session_registe r('content-type');
    session_registe r('file-name');
    session_registe r('jobid');
    $jobid = time();

    //rename the file with the jobid before it,

    $rename = $jobid . $_FILES['userfile']['name']; //or $rename =
    $username;
    $file_name = $_FILES['userfile']['name'];
    $read_extension = explode(".", $file_name);
    $ext = $read_extension[1];
    rename($file_na me, $rename);

    } else {

    $msg = "File did not upload successfully, close window and try
    again\n";
    $msg = $msg . print_r($_FILES );

    }


    ?>
  • Shawn Wilson

    #2
    Re: file upload - weird!

    Amy Kimber wrote:[color=blue]
    >
    > Hello all,
    >
    > ok, I have a file upload secton to my site, two pages, one with a
    > form and one that does the uploading.... some files upload fine, other
    > don't
    >
    > an exe of 300k will upload, but a word document of 40k wont and so on,
    > in the php.ini a limit of 2mb is set (I haven't changed it, it's how
    > the file originally as, so it isn't my maths that's gone mad).
    >
    > The code was taken more or less from the php manual... any iedas
    > people? Please? I'm going mad! And just when I was starting to enjoy
    > PHP :-(
    >
    > <?php
    >
    > session_start() ;
    >
    > $uploaddir = '/home/sites/site1/web/translation/';
    >
    > $uploadfile = $uploaddir . $_FILES['userfile']['name'];
    >
    > if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile))
    > {
    >
    > $msg = "File (" . $_FILES['userfile']['name'] . ") is valid, and
    > was successfully uploaded. ";
    > //print_r($_FILES );
    > session_registe r('content-type');
    > session_registe r('file-name');
    > session_registe r('jobid');
    > $jobid = time();
    >
    > //rename the file with the jobid before it,
    >
    > $rename = $jobid . $_FILES['userfile']['name']; //or $rename =
    > $username;
    > $file_name = $_FILES['userfile']['name'];
    > $read_extension = explode(".", $file_name);
    > $ext = $read_extension[1];
    > rename($file_na me, $rename);
    >
    > } else {
    >
    > $msg = "File did not upload successfully, close window and try
    > again\n";
    > $msg = $msg . print_r($_FILES );
    >
    > }
    >
    > ?>[/color]

    Are you maybe uploading a file you already uploaded and renamed (shot in the
    dark)?

    I.E.
    You upload text.doc.
    text.doc moved to your upload directory.
    text.doc got renamed to 1234567890text. doc.
    You downloaded 1234567890text. doc to make sure it went through okay.
    You upload 1234567890text. doc.
    1234567890text. doc produces an error when moved to upload directory because it
    already exists there.


    If that's not what's happening:
    What are some sample filenames of files that will and won't upload?
    By "won't upload" do you mean you get your "else" error message or the file is
    corrupted?
    If your file is corrupted, how are you checking it?

    Regards,
    Shawn
    --
    Shawn Wilson
    shawn@glassgian t.com


    I have a spam filter. Please include "PHP" in the
    subject line to ensure I'll get your message.

    Comment

    Working...