Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中自动生成bit.ly URL不起作用_Php - Fatal编程技术网

在php中自动生成bit.ly URL不起作用

在php中自动生成bit.ly URL不起作用,php,Php,我有一个小问题(我想) 我的网站会生成一个链接,我想缩短这个链接 这是我的代码: <?php error_reporting(0); include("config.php"); if(isset($_POST["sub"])) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br>"; } else { $r = rand(1,

我有一个小问题(我想)

我的网站会生成一个链接,我想缩短这个链接

这是我的代码:

<?php
error_reporting(0);
include("config.php");
if(isset($_POST["sub"])) {
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
  }
else
  {
    $r = rand(1,100000);
    $filename = $r . $_FILES["file"]["name"];
  if (file_exists("upload/" . $filename)) {
    echo "<center>";
      echo $_FILES["file"]["name"] . " already exists. Please Rename your file and try again.</center><br>";
  }
else
  {
  $link="$baseurl/upload/" . $filename;
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $filename);
  echo "<center>Direct Download link: <a href=\"$link\">$link</a></center><br>";
  }
 }
}

include("main.html");
?>

所以我没有得到的是,如果我在这一行中输入:make_bitly_url('>>>$link您试图回显变量$link,它被单引号包围

您应该在字符串周围使用引号,而不是变量。但是,如果您使用双引号,您可以直接在字符串中回显变量,但是,我个人建议您始终使用单引号,并用点分隔变量

 <?php
 $var = 'variable';
 //echo string
 echo 'test this is a ';
 echo $var;
 echo '!';

 //previous 2 echos show: "test this is a variable!", however you could concatenate it like this:
 echo 'test this is a '.$var.'!';
 ?>
致:


$short=make_bitly_url('link','dsfser','R_5aafdd2f8d67f78150e52fbd0613519','json');
更改为
$short=make_bitly_url('link','dsfser','R_5aafdd2f8d67f78150e52fbd06613519','json'));
使用“$var”将防止用字符串替换$var。谢谢你的解决方案!我还没有学过php,所以我还在学习!谢谢!检查一下。阅读“单引号”和“双引号”链接。
 <?php
 $var = 'variable';
 //echo string
 echo 'test this is a ';
 echo $var;
 echo '!';

 //previous 2 echos show: "test this is a variable!", however you could concatenate it like this:
 echo 'test this is a '.$var.'!';
 ?>
$short = make_bitly_url('$link','dsfser','R_5aafdd2f8d67f78150e52ffbd0613519','json');
$short = make_bitly_url($link,'dsfser','R_5aafdd2f8d67f78150e52ffbd0613519','json');