0

PHP を実行している Web サーバーに大きなファイルをアップロードするアプリを開発しようとしています。すぐに、ファイルが正しく分割されていないという問題に遭遇しました。

現在、私はこのコードを持っています

string adrese = "c:\\directory\\file.jpg";
int garums = 16384;
String ext = Path.GetExtension(adrese);

FileStream file = /*/File.Open(adrese, FileMode.Open);/*/
    new FileStream(adrese, FileMode.Open, System.IO.FileAccess.Read);
long fgar = file.Length; //100%
long counter = garums;
first = true;
byte[] chunk = new byte[garums];

while (true)
{
    int index = 0;
    //long Controll = counter+garums;
    while (index < chunk.Length)
    {
        int bytesRead = file.Read(chunk, index, chunk.Length - index);
        if (bytesRead == 0)
        {
            /*byte[] biti = new byte[index];
            for (int i = 0; i < index; i++)
            {
                biti[i] = chunk[i];
            }
            chunk = new byte[index];
            chunk = biti;*/
            break;
        }
        index += bytesRead;
    }

    if (index != 0) // Our previous chunk may have been the last one
    {
        byte[] biti = new byte[index];
        for (int i = 0; i < index; i++)
        {
            biti[i] = chunk[i];
        }
        chunk = new byte[index];
        chunk = biti;
        // index is the number of bytes in the chunk
        sutam(Convert.ToBase64String(chunk),ext);
    }

    double procentuali = ((counter * 100) / fgar);
    if (procentuali > 99)
    {
        procentuali = 100;
    }

    progressBar1.Value = (int)Math.Round(procentuali);
    label1.Text = "" + procentuali;

    counter = counter+garums;
    if (index != garums) // We didn't read a full chunk: we're done
    {
        return;
    }
}

file.Close();

1に設定するとすべてが機能garumsしますが、数 GB のサイズのファイルをアップロードするのに 1 年ほど待つ人がいるでしょうか。

何がおかしいのか、どうすれば直せるのか教えていただけると幸いです。

4

1 に答える 1