Php 我可以用cURL执行这样的动作吗?
我需要给我的图像一个扩展名,这取决于它们的类型,并且为它们创建一个全新的名称。我可以在将文件发送到服务器之前获取扩展名吗?Php 我可以用cURL执行这样的动作吗?,php,curl,Php,Curl,我需要给我的图像一个扩展名,这取决于它们的类型,并且为它们创建一个全新的名称。我可以在将文件发送到服务器之前获取扩展名吗? $\u POST['image']是图像的URL$new\u name应在运行交换机时添加 $image = $_POST['image']; $ch = curl_init($image); curl_setopt($ch, CURLOPT_HEADER, 0); $imagedata = curl_exec($ch); list($width, $height, $
$\u POST['image']
是图像的URL<代码>$new\u name应在运行交换机时添加
$image = $_POST['image'];
$ch = curl_init($image);
curl_setopt($ch, CURLOPT_HEADER, 0);
$imagedata = curl_exec($ch);
list($width, $height, $type) = getimagesize($filename);
switch ($type) {
case 1: ....... //Give the filename a .gif extension and so on for every filetype
}
$fp = fopen('../images/' . $new_name, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_close($ch);
fclose($fp);
!找到答案了!(很抱歉,如果我回答错了自己的问题(通过简单的“编辑”问题),请评论如何正确回答,如果我错了;)
我只需要运行cURL函数两次,但名称不同。第一个简单地获取文件的信息,第二个用$new\u name
$image=$_POST['image']
$ch=curl_init($image);curl_setopt($ch,CURLOPT_头,0);
$imagedata=curl\u exec($ch)$info=curl\u getinfo($ch,
卷发信息(内容类型);卷曲关闭($ch)
if($info==“image/jpeg”)//运行一个代码,该代码将为图像提供
适当的扩展
$cf=curl_init($image)$fp=fopen(“../images/”.“image.jpg”,
"wb";;curl_setopt($cf,CURLOPT_文件,$fp);curl_exec($cf);
卷曲关闭($cf);fclose($fp)
用它来打字,但这样的结构可以应用吗?对不起,不知道你的意思是说我在卷曲中间运行代码。