如果我使用jpg图像但不使用bmp图像,我的代码工作正常。 它显示文件不可写。 这是我的C#代码:
string fileName = @"E:\ProjectPics\new.BMP";
if (fileName != "")
{
string path = "http://localhost/Images/upload.php";
WebClient client = new WebClient();
byte[] responseBinary = client.UploadFile(path, fileName);
string response = Encoding.UTF8.GetString(responseBinary);
}
这是我的php代码:
<?php
//check whether the folder the exists
if(!(file_exists('upload')))
{
//create the folder
mkdir('upload');
//give permission to the folder
chmod('upload/', 0777);
}
$uploads_dir = './upload'; //Directory to save the file that comes from client application.
if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
else
{
die("Upload failed with error " . $_FILES['file']['error']);
}
?>