保存Facebook个人资料图像时,检查图像文件是否可用于卷曲。 PHP

时间:2016-09-21 05:33:45

标签: php facebook-graph-api php-curl save-image

在我的项目中,当用户从<Page x:Class="ImageGalerry.ItemDetailPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:common="using:ImageGalerry.Common" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:data="using:ImageGalerry.Data" xmlns:local="using:ImageGalerry" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" mc:Ignorable="d"> <Grid d:DataContext="{Binding Groups[0].Items[0], Source={d:DesignData Source=/DataModel/DataItem.json, Type=data:DataItemSource}}" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid.RowDefinitions> <RowDefinition Height="140" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <!-- Back button and page title --> <Grid Background="#FF6996D1" DataContext="{Binding Item}"> <Grid.ColumnDefinitions> <ColumnDefinition Width="1366" /> </Grid.ColumnDefinitions> <Button x:Name="backButton" Margin="39,59,0,0" VerticalAlignment="Top" AutomationProperties.AutomationId="BackButton" AutomationProperties.ItemType="Navigation Button" AutomationProperties.Name="Back" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}" Style="{StaticResource NavigationBackButtonNormalStyle}" /> <TextBlock x:Name="pageTitle" Margin="120,40,30,40" VerticalAlignment="Top" IsHitTestVisible="false" Style="{StaticResource HeaderTextBlockStyle}" Text="{Binding Title}" TextWrapping="NoWrap" /> <!--<MediaElement x:Name="mediaplayer" Source="images/ost.mp3" AudioCategory="BackgroundCapableMedia" /> <Button x:Name="PlayButton" Content="Stop" Click="PlayButton_Click" Margin="1274,72,0,30" />--> </Grid> <Grid x:Name="contentRegion" Grid.Row="1" Background="#FF6996D1"> <FlipView ItemsSource="{Binding Group.Items}" SelectedItem="{Binding Item, Mode=TwoWay}"> <FlipView.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" /> </ItemsPanelTemplate> </FlipView.ItemsPanel> <FlipView.ItemTemplate> <DataTemplate> <Grid> <Image Width="732" Height="559" Margin="84,20,0,49" HorizontalAlignment="Left" VerticalAlignment="Center" Source="{Binding ImagePath}" /> <ScrollViewer x:Name="myScroll" Margin="852,60,50,91" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" VerticalScrollMode="Auto"> <TextBlock Width="425" Height="2210" FontSize="27" Text="{Binding Description}" TextAlignment="Justify" TextWrapping="Wrap" /> </ScrollViewer> </Grid> </DataTemplate> </FlipView.ItemTemplate> </FlipView> </Grid> </Grid> </Page> 登录时,将保存个人资料照片。这是工作。但是如果没有图像,那么Facebook文件也会保存。

如何检查网址包含图片并仅在图片可用时保存

PHP示例代码如下所示

0 Byte

1 个答案:

答案 0 :(得分:2)

您可以随时使用curl_getinfo()检查卷曲返回的标题信息(php.net处的更多内容)

因此,在您的情况下,您可以curl_getinfo($curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD)查看返回的字节数。

另外我认为如果找不到图像,Facebook应该返回不同的HTTP代码,因此您可以尝试curl_getinfo($curl, CURLINFO_HTTP_CODE)。如果找到图片,则应为200,如果没有,则为404