由于上面发布的错误,当表单被汇总时,我收到了该错误。我不是100%确定可能是什么原因,但我已经提供了你需要的所有部件。供参考Snapchat :: MEDIA_IMAGE = 0.
这是使用this。
表单HTML
<form role="form" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="form-group">
<label class="col-lg-2 control-label">
Select Snap </label>
<div class="col-lg-10" style="margin-bottom:24px;">
<input type="file" id="file" class="filestyle" data-icon="false" name="file" data-classbutton="btn btn-default" data-classinput="form-control inline input-s">
<span class="help-block m-b-none">
Here, select the snapchat that you'd like to send. </span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">
Recipient </label>
<div class="col-lg-10">
<button data-toggle="dropdown" class="btn btn-sm btn-default dropdown-toggle">
<span class="dropdown-label" data-placeholder="Please select">
Please select </span>
<span class="caret">
</span>
</button>
<ul name="dropdown" class="dropdown-menu dropdown-select">
<li>
<a href="#">
<input type="checkbox" name="d-s-c-1">
Option1 </a>
</li>
<li>
<?php
$ff = count($r['friends']);
for($xx = 0; $xx < $ff; $xx++)
{
echo ' <li>
<a href="#">
<input type="checkbox" name="d-s-c-1[]" value="'.$r['friends'][$xx]->name.'">
'.$r['friends'][$xx]->name.'</a>
</li>';
}
?>
</ul>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox">
<label>
<input type="checkbox">
Remember me </label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-sm btn-default">
Send Snap! </button>
</div>
</div>
</form>
表格PHP(同一页面)
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
$filename = $_FILES["file"]["name"];
$type = $_FILES["file"]["type"];
$size = $_FILES["file"]["size"];
$location = $_FILES["file"]["tmp_name"];
$new = "upload/" . $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], 's/' . $filename);
$aDoor = $_POST['d-s-c-1'];
if(empty($aDoor))
{
echo("Please Select a recipient.");
}
else
{
$N = count($aDoor);
$id = $s->upload(
Snapchat::MEDIA_IMAGE,
file_get_contents($new)
);
for($i=0; $i < $N; $i++)
{
$s->send($id, array($aDoor[$i]), 8);
}
}
}
?>
upload()&amp;发送()
public function upload($type, $data) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
// To make cURL happy, we write the data to a file first.
$temp = tempnam(sys_get_temp_dir(), 'Snap');
file_put_contents($temp, parent::encryptECB($data));
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
$cfile = curl_file_create($temp, ($type == self::MEDIA_IMAGE ? 'image/jpeg' : 'video/quicktime'), 'snap');
}
$media_id = strtoupper($this->username) . '~' . time();
$timestamp = parent::timestamp();
$result = parent::post(
'/upload',
array(
'media_id' => $media_id,
'type' => $type,
'data' => (version_compare(PHP_VERSION, '5.5.0', '>=') ? $cfile : '@' . $temp . ';filename=data'),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
),
TRUE
);
unlink($temp);
return is_null($result) ? $media_id : FALSE;
}
/**
* Sends a snap.
*
* @param string $media_id
* The media ID of the snap to send.
* @param array $recipients
* An array of recipient usernames.
* @param int $time
* The time in seconds the snap should be available (1-10). Defaults to 3.
*
* @return bool
* TRUE if successful, FALSE otherwise.
*/
public function send($media_id, $recipients, $time = 3) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/send',
array(
'media_id' => $media_id,
'recipient' => implode(',', $recipients),
'time' => $time,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
}