Php 为什么在我将图像上传到Azure后我无法访问它?
我正在为WindowsPhone8.1开发一个通用应用程序,但我正在使用PHP页面从上传到我的服务的图像中识别一些模式 我发现在我将X图像上传到Azure之后,我无法使用它。我正在使用WebMatrix开发我的PHP页面,当我刷新它时,它不会显示我上载的图像,但是当我尝试发布某些内容时,我选择了选项:“删除远程服务器上不在我计算机上的文件。”我可以看到我的图像。这是我的PHP代码的一个示例:Php 为什么在我将图像上传到Azure后我无法访问它?,php,azure,file-upload,windows-runtime,windows-phone-8.1,Php,Azure,File Upload,Windows Runtime,Windows Phone 8.1,我正在为WindowsPhone8.1开发一个通用应用程序,但我正在使用PHP页面从上传到我的服务的图像中识别一些模式 我发现在我将X图像上传到Azure之后,我无法使用它。我正在使用WebMatrix开发我的PHP页面,当我刷新它时,它不会显示我上载的图像,但是当我尝试发布某些内容时,我选择了选项:“删除远程服务器上不在我计算机上的文件。”我可以看到我的图像。这是我的PHP代码的一个示例: $uploaddir = getcwd(); $uploadfile = $uploaddir . &q
$uploaddir = getcwd();
$uploadfile = $uploaddir . "/" . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
chmod($uploadfile, 0755);
$Test = new Display($_FILES['userfile']['name']);
echo '{"result": "' . $Test->getNumber($_REQUEST['color'], false) . '"}';
//unlink($uploadfile);
} else {
echo '{"result": "-1"}';
}
我想知道我的bug是什么,因为我不明白为什么我也可以从URL访问到我不能使用的部分,也许是我如何分配权限的,但无论是否使用chmod,它都不会改变。我甚至尝试过其他主机,当我进入文件管理器时,问题也是一样的,只有我的PHP文件,它不允许我管理图像
这是我的Windows Phone代码,用于在必要时上载图像:
byte[] ConvertBitmapToByteArray()
{
WriteableBitmap bmp = bitmap;
using (Stream stream = bmp.PixelBuffer.AsStream())
{
MemoryStream memoryStream = new MemoryStream();
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}
public async Task<string> Upload()
{
try
{
using (var client = new HttpClient())
{
using (var content =
new MultipartFormDataContent())
{
byte[] data = ConvertBitmapToByteArray();
using (var stream = new InMemoryRandomAccessStream())
{
// encoder *outputs* to stream
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream);
// encoder's input is the bitmap's pixel data
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight,
(uint)bitmap.PixelWidth, (uint)bitmap.PixelHeight, 96, 96, data);
await encoder.FlushAsync();
content.Add(new StreamContent(stream.AsStream()), "userfile", fileNewImage);
using (
var message =
await client.PostAsync("http://xplace.com/uploadtest.php", content))
{
var input = await message.Content.ReadAsStringAsync();
return input;
}
}
}
}
}
catch (Exception ex)
{
return null;
}
}
byte[]ConvertBitmapToByteArray()
{
WriteableBitmap bmp=位图;
使用(Stream Stream=bmp.PixelBuffer.AsStream())
{
MemoryStream MemoryStream=新的MemoryStream();
stream.CopyTo(memoryStream);
返回memoryStream.ToArray();
}
}
公共异步任务上载()
{
尝试
{
使用(var client=new HttpClient())
{
使用(var)内容=
新的MultipartFormDataContent())
{
字节[]数据=ConvertBitmapToByteArray();
使用(var stream=new InMemoryRandomAccessStream())
{
//编码器*输出*到流
var编码器=等待BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId,流);
//编码器的输入是位图的像素数据
编码器.SetPixelData(BitmapPixelFormat.Bgra8,BitmapAlphaMode.Straight,
(uint)bitmap.PixelWidth,(uint)bitmap.PixelHeight,96,96,数据);
等待编码器。FlushAsync();
添加(新的StreamContent(stream.AsStream()),“userfile”,fileNewImage);
使用(
var消息=
等待客户端。PostAsync(“http://xplace.com/uploadtest.php“,内容))
{
var input=wait message.Content.ReadAsStringAsync();
返回输入;
}
}
}
}
}
捕获(例外情况除外)
{
返回null;
}
}
感谢您的宝贵知识和经验。创建blob存储帐户,并添加公共容器。在保存文件的操作中,将文件存储在blob存储容器中。然后,您可以像访问任何其他图像一样访问该图像 以下是有关Azure的教程: 此外,您不能在容器中创建文件夹,但可以使用blobrefname上的命名约定来创建容器的概念。此外,如果希望URL具有特定外观,可以将域附加到云服务 希望这有帮助! 干杯 再次阅读您的问题-看起来更多的是在客户端。 以下是我通常将文件附加到
MultipartFormDataContent
:
MultipartFormDataContent content = new MultipartFormDataContent();
FileInfo info = new FileInfo(currFileLoc);
string contentMediaType = null;
//This is a Dictionary<string, string> that takes in the file
//extension, and returns the media type (e.g. "image/jpeg")
GlobalVariables.ApprovedMediaTypes.TryGetValue(
info.Extension.ToLower()
, out contentMediaType);
//If the dictionary doesn't return a result
//then it's not a supported file type
if (contentMediaType == null)
throw new Exception(
String.Format("The file \"{0}\" is an unsupported file type."
, info.Name));
ByteArrayContent currFile = new ByteArrayContent(File.ReadAllByte(currFileLoc));
currFile.Headers.ContentType = new MediaTypeWithQualityHeaderValue(contentMediaType);
content.Add(currFile, currFileLoc, currFileLoc);
MultipartFormDataContent=new MultipartFormDataContent();
FileInfo=newfileinfo(currFileLoc);
字符串contentMediaType=null;
//这是一本收录该文件的词典
//扩展名,并返回媒体类型(例如“图像/jpeg”)
GlobalVariables.ApprovedMediaTypes.TryGetValue(
info.Extension.ToLower()
,out contentMediaType);
//如果字典没有返回结果
//那么它不是受支持的文件类型
if(contentMediaType==null)
抛出新异常(
Format(“文件\“{0}\”是不受支持的文件类型。”
,info.Name));
ByteArrayContent currFile=新的ByteArrayContent(File.ReadAllByte(currFileLoc));
currFile.Headers.ContentType=新的MediaTypeWithQualityHeaderValue(contentMediaType);
添加(currFile、currFileLoc、currFileLoc);
我打电话的那个人。也许您找到了blob存储的另一种选择。最后,如果您加载大文件,您可能需要考虑分块上传
~z~干杯