如何编辑php中的反向标记内的参数?

时间:2018-01-29 21:16:11

标签: php python apache shell arguments

所以我想要做的是利用php中的反引号运算符来运行一些将在我的Apache Localhost上显示的python代码。这个python代码包含编辑参数的功能,但是当我尝试编辑参数时,我的localhost网站上没有任何内容。

我的代码:

<!DOCTYPE html>
<html>
<head>
  <title>Upload your files</title>
</head>
<body>
  <form enctype="multipart/form-data" action="upload.php" method="POST">
    <p>Upload your file</p>
    <input type="file" name="uploaded_file"></input><br />
    <input type="submit" value="Upload"></input>
  </form>
</body>
</html>
<?PHP
  if(!empty($_FILES['uploaded_file']))
  {
    $path = "uploads/";
    $path = $path . basename( $_FILES['uploaded_file']['name']);
    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
      echo "The file ".  basename( $_FILES['uploaded_file']['name']). 
      " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
  }
?>
<?PHP 
   $python = `python classify_image.py --image_file C:\xampp\htdocs\uploads\bamboo.jpg`;
   echo $python;
?>

这是我在Localhost中看到的: With the modified argument

但是当我删除&#34; --image_file C:\ xampp \ htdocs \ uploads \ bamboo.jpg&#34;从反引号中,python代码恢复为读取默认图像并在我的localhost上返回: Without the modified argument

有人能告诉我在php中使用反引号运算符有什么问题吗?

1 个答案:

答案 0 :(得分:0)

您可以在反引号中使用变量。

您还应该将if电话放在<?PHP if(!empty($_FILES['uploaded_file'])) { $path = "uploads/"; $path = $path . basename( $_FILES['uploaded_file']['name']); if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) { echo "The file ". basename( $_FILES['uploaded_file']['name']). " has been uploaded"; $python = `python classify_image.py --image_file C:/xampp/htdocs/$path`; echo $python; } else{ echo "There was an error uploading the file, please try again!"; } } ?> 内,这样您才能在文件成功上传后才能这样做。

在路径名中使用正斜杠而不是反斜杠,或者使用反斜杠加倍。在双引号和反引号中,反斜杠是一个转义前缀,导致错误地解析路径名。

const fetchPrices = () =>{`
 return async (dispatch) =>{`
 try {
   dispatch(startFetch())
   let data = await axios.get('mybackendurl')
   dispatch(fetchSucc(data))
 } catch (error) {
   dispatch(fetchFail({err:'failed to get shit'}))
  }
 }
}