0

Ajax Async File Uploaderを使用して画像ファイルを取得し、フォルダーに保存しています。

    if( file != null && file.hasFile)
    {
      if( file is the appropriate file type)
      {
        if( the filename is already taken)
        {
          add random numbers on the file name until it's unique
        }

        file.SaveAs( filepath + filename );
      }
    }

これは私のローカルコンピュータでうまく機能します。ただし、プログラムをサーバーに公開すると、ファイルは正しい場所に正しい名前で保存されますが、ファイルサイズは0です。ファイルを開くことができません。

私は何が間違っているのですか?

これが私の実際のコードです:

     // If cert has a file
    if(cert != null && cert.HasFile)
    {
    // If cert is the appropriate file type
    if((cert.FileName.IndexOf(".jpg", StringComparison.OrdinalIgnoreCase) < 0) &&
    (cert.FileName.IndexOf(".jpeg", StringComparison.OrdinalIgnoreCase) < 0) &&
    (cert.FileName.IndexOf(".tiff", StringComparison.OrdinalIgnoreCase) < 0) &&
    (cert.FileName.IndexOf(".png", StringComparison.OrdinalIgnoreCase) < 0) &&
    (cert.FileName.IndexOf(".gif", StringComparison.OrdinalIgnoreCase) < 0) &&
    (cert.FileName.IndexOf(".pdf", StringComparison.OrdinalIgnoreCase) < 0))
            {
                // Popup warning
                Session["imagePopup"] = "true";
            }
            else
            {
                string filename = cert.FileName;

                // If image already exists randomly add numbers until a unique filename is found
                while( File.Exists(System.Configuration.ConfigurationManager.AppSettings["CertificateSavePath"] + filename))
                {
                    Random r = new Random();

                    filename = filename.Insert(0, r.Next(99).ToString());
                }


                // Save the new file
                try
                {
                    // save the file
                    cert.SaveAs(System.Configuration.ConfigurationManager.AppSettings["CertificateSavePath"] + filename);
                }
                catch(Exception ex)
                {
                    error.Text += ex.Message + "<br />";
                }
4

1 に答える 1

0

それを私が直した。

私は次のようにプログラムを実行していました:

編集可能な行を含むリスト ビューを作成しました。ユーザーは画像をアップロードでき、画像は保存されます。ユーザーが「更新」をクリックすると、画像が保存されます。

私はこれを次のように変更しました:

更新イベントが成功すると、イメージはすぐに保存されます。「更新」をクリックすると、ページが更新されます。

これが誰かを助けることを願っています

于 2013-03-14T18:10:17.630 に答える