Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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 禁止错误访问_Php_Javascript_Json_Twitter_Web - Fatal编程技术网

Php 禁止错误访问

Php 禁止错误访问,php,javascript,json,twitter,web,Php,Javascript,Json,Twitter,Web,我遇到错误,我的php,我不知道它是什么。。。上面写着“禁止进入 您没有访问请求对象的权限。该对象受读取保护,或者服务器不可读 如果您认为这是服务器错误,请联系网站管理员 错误403 twitter_sample.com Apache/2.4.3(Win32)OpenSSL/1.0.1c PHP/5.4.7“ 我的代码是 <?php if($_POST) { $file=$_FILES['media']; $postfields = array(); $postfield

我遇到错误,我的php,我不知道它是什么。。。上面写着“禁止进入

您没有访问请求对象的权限。该对象受读取保护,或者服务器不可读

如果您认为这是服务器错误,请联系网站管理员

错误403

twitter_sample.com Apache/2.4.3(Win32)OpenSSL/1.0.1c PHP/5.4.7“

我的代码是

<?php

if($_POST)
{

  $file=$_FILES['media'];
  $postfields = array();

  $postfields['username'] = $_POST['username'];

  $postfields['password'] = $_POST['password'];
  $postfields['message'] = $_POST['message'];
  $postfields['media'] = "@$file[tmp_name]";

  $t=new twitpic($postfields,true,true);
  $t->post();
  exit;
}

?>

<style type="text/javascript">
  *{font-family:verdana;}
  span{font-size:12px;color:#393939;}
  h3{font-size:14px;color:#5AAAF7;}
</style>
<body>

  <h3>Upload your pic to twitpic, and post status on twitter</h3>
  <form method="post"  enctype="multipart/form-data" action="<?= $_SERVER[PHP_SELF] ?>"   >
    <p><span style="height:40px;font-weight:bold;margin-right:56px;">Twitter Username :</span><input type="text" name="username" /></p>
    <p><span style="height:40px;font-weight:bold;margin-right:61px;">Twitter Password:</span><input type="password" name="password" /></p>

    <p><span style="vertical-align:text-top;height:40px;font-weight:bold;margin-right:28px;">Message to be posted :</span> <textarea cols="35" rows="2" name="message"></textarea></p>
    <p><span style="vertical-align:text-top;height:40px;font-weight:bold;">Choose an image to upload: </span><input type="file" name="media" /></p>
    <p style="width:250px;text-align:right;margin-top:50px;"><input type="submit" value="Upload&nbsp;&raquo;" /> </p>
  </form>
  <sup>Script powered by <a href="http://www.digimantra.com/">www.digimantra.com</a></sup>
</body>

You can skip posting update to twitter by passing the third argument as false or just by skipping it. If you want to upload image programmatically, without the user input or the form then you can do it using the following code. Make sure the image path is correctly mention, else it will throw an error.

<?php
$file='file_to_be_uploaded.gif';
$postfields = array();

$postfields['username'] = 'twitter_username';

$postfields['password'] = 'twitter_password';
$postfields['message'] = 'Message to be posted' ;
$postfields['media'] = "@$file"; //Be sure to prefix @, else it wont upload

$t=new twitpic($postfields,true,true);
$t->post();
?>

*{字体系列:verdana;}
span{字体大小:12px;颜色:#3939;}
h3{字体大小:14px;颜色:#5AAAF7;}
将你的照片上传到twitpic,并在twitter上发布状态



谢谢…

我不知道这是否是问题所在,但在localhost中,您必须使用:

$postfields['username']=addslashes($\u POST['username'])

而不是


$postfields['username']=$\u POST['username']

您的web服务器设置可能有问题,与您的PHP脚本无关。我正在本地主机中运行它。。。这就是问题所在?这可能是文件夹权限的问题-您使用的是什么web服务器,您从哪个文件夹提供文件服务?web服务器,是xampp吗?因为我使用的是xampp,而我的操作系统是windows7。如果你只有一个普通的html文件,那么它通过web服务器工作吗?
<?php

class twitpic
{
  /* 
   * variable declarations
   */
  var $post_url='http://twitpic.com/api/upload';
  var $post_tweet_url='http://twitpic.com/api/uploadAndPost';
  var $url='';
  var $post_data='';
  var $result='';
  var $tweet='';
  var $return='';

/*
* @param1 is the array of data which is to be uploaded
* @param2 if passed true will display result in the XML format, default is false
* @param3 if passed true will update status twitter,default is false
*/

  function __construct($data,$return=false,$tweet=false)
  {
    $this->post_data=$data;
    if(empty($this->post_data) || !is_array($this->post_data)) //validates the data
      $this->throw_error(0);
    $this->display=$return;
    $this->tweet=$tweet;

  }

  function post()
  {
    $this->url=($this->tweet)?$this->post_tweet_url:$this->post_url; //assigns URL for curl request based on the nature of request by user
    $this->makeCurl();
  }
  private function makeCurl()
  {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl, CURLOPT_HEADER, false);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($curl, CURLOPT_URL, $this->url);
    curl_setopt($curl, CURLOPT_POST, 3);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $this->post_data);
    $this->result = curl_exec($curl);
    curl_close($curl);
    if($this->display)
    {
      header ("content-type: text/xml");
      echo $this->result ;
    }

  }
  private function throw_error($code) //handles few errors, you can add more

  {
    switch($code)
    {
      case 0:
        echo 'Think, you forgot to pass the data';
        break;
      default:
        echo 'Something just broke !!';
        break;
    }
    exit;
  }
} //class ends here

?>