Im trying to get this very basic script to upload .swf files to my server with no luck.
I get an invalid file error when i try to upload.
.jpg,gifs,pngs all upload fine.
I tried changing a few things putting swf where jpg is etc. but no joy.
Is it not possible to upload swf files in this way?
and help appreciated, many thanks.
`
Filename:
<?php
$allowedExts = array("gif", "jpeg", "jpg","swf","png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "application/x-shockwave-flash/swf")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 8388608)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?> `
function addAdFields($post,$files){
//print_r( $files);
$allowedExts = array("gif", "jpeg", "jpg", "png" ,"tiff","tif","swf");
$fileType=$files["bannerType"]["type"];
$tmpName=$files["bannerType"]["tmp_name"];
$fileName=$files["bannerType"]["name"];
$imageName = mysql_real_escape_string($files["bannerType"]["name"]);
$imageData = mysql_real_escape_string(file_get_contents($files["bannerType"]["tmp_name"]));
$imageType = mysql_real_escape_string($files["bannerType"]["type"]);
list($width, $height, $type, $attr) = getimagesize($tmpName);
$dimArr= array($width, $height);
$temp = explode(".", $fileName);
$files["bannerType"]["name"];
$extension = end($temp);
$fileTmpName= mysql_real_escape_string($tmpName);
$curDate = "";
$ipadd = $_SERVER['REMOTE_ADDR'];
$camDetail=explode('_',$post['campaignType']);
$this -> tableName = "_ads";
$this -> fieldValues['campaignID'] = $camDetail[0];
$this -> fieldValues['campaignName'] =$camDetail[1];
$this -> fieldValues['adTitle'] = $post['adTitle'];
$this -> fieldValues['bannerID'] = $post['bannerType'];
if($_SESSION['bannerTyp']=='Placement')
{
$this -> fieldValues['uploadFileName'] = $post['placementText'];
}
else{
$this -> fieldValues['uploadFileName'] = $imageName;
$this -> fieldValues['uploadedFile'] = $imageData;
}
$this -> fieldValues['dimantation'] = json_encode($dimArr);
$this -> fieldValues['addDateTime'] = $curDate;
$this -> fieldValues['addIpAddress'] = $ipadd;
$this->insert();
//echo $this->query;
header('Location: main.html?action=add-ads&menuid=155');
}
Related
When I want to upload pdf or ms word files I get this error:
The file must be a file of type: pdf, doc, docx
this is my controller:
public function store(BookRequest $request)
{
$book = new Book();
$book->title = $request->input('title');
$book->isbn = $request->input('isbn');
$book->$author = $request->input('author');
$book->$description = $request->input('description');
if($request->hasFile('file'))
{
$file = $request->file('file');
$fileName = date('Y') . "_" . $file->getClientOriginalName();
$distination_path = 'books/';
$file->move($distination_path, $fileName);
$book->book_path = $distination_path . $fileName;
}
$book->user_id = \Auth::user()->id;
$book->save();
return redirect('/library')->with('message','کتاب موفقانه آپلود شد.')->withErrors('مشکل رخداد');
}
And the Request:
public function rules()
{
return [
'title'=>'required',
'author'=>'required',
'isbn'=>'required',
'file'=>'required|mimes:pdf,doc,docx',
];
}
To answer the question (As it might made the Question fulfill)
Remove the $ from $author and $description
i.e., Change the below code to
$book->$author = $request->input('author');
$book->$description = $request->input('description');
like this
$book->author = $request->input('author');
$book->description = $request->input('description');
Hope, it will helpful for future readers
I need to develop an iOS app that fetches data from an OpenCart installation online. This includes ordering online, adding things to wish list, creating a user account. Logging in to an already existing user account and everything else that open cart offers. Basically, it is an iOS version of the OpenCart website that connects to the OpenCart's MySQL database.
I googled a little bit but couldn't find a proper API that I can use to hookup my app with OpenCart. What other options do I have? Does OpenCart offer any web service? (Like WordPress offers XML-RPC). Or is there a good API that I can use?
Unfortunately, OpenCart does not offer any API straight away. (that's for an answer).
There is an opensource OpenCart API project on GitHub that you can download (google it, I do not remember it's name) but this offers only the very limited and basic methods for just reading of data (if I remember correctly there were methods for getting the list of categories, list of products and product details and few more).
This could be your starting point: fork, add methods, share. Or create your own API from a scratch if you wish (again, sharing will be highly welcomed :-) - I believe you could even find users willing to pay for it - I would have created one if I had time - but sadly I have not...).
<?php
include_once 'functions.php';
class ControllerJsonJson extends Controller {
public function index() {
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
if ($child['image']) {
$childpopup = $this->model_tool_image->resize($child['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
$childthumb = $this->model_tool_image->resize($child['image'], 74,74);
} else {
$childthumb='';
$childpopup = '';
}
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'popup'=>$childpopup,
'thumb'=>$childthumb,
'id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
if ($category['image']) {
$categorypopup = $this->model_tool_image->resize($category['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
$categorythumb = $this->model_tool_image->resize($category['image'], 74,74);
} else {
$categorypopup = '';
$categorythumb='';
}
// Level 1
$data['categories'][] = array(
'popup' => $categorypopup,
'thumb' => $categorythumb,
'id' => $category['category_id'],
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
);
}
}
$obj=new functions();
echo $obj->json_pretty_encode($data);
}
}
<?php
class functions {
//put your code here
public function json_pretty_encode($obj){
header("Content-type: application/json");
$json = json_encode($obj);
if (!$json) return $json;
$f = '';
$len = strlen($json);
$depth = 0;
$newline = false;
for ($i = 0; $i < $len; ++$i)
{
if ($newline)
{
$f .= "\n";
$f .= str_repeat(' ', $depth);
$newline = false;
}
$c = $json[$i];
if ($c == '{' || $c == '[')
{
$f .= $c;
$depth++;
$newline = true;
}
else if ($c == '}' || $c == ']')
{
$depth--;
$f .= "\n";
$f .= str_repeat(' ', $depth);
$f .= $c;
}
else if ($c == '"')
{
$s = $i;
do {
$c = $json[++$i];
if ($c == '\\')
{
$i += 2;
$c = $json[$i];
}
} while ($c != '"');
$f .= substr($json, $s, $i-$s+1);
}
else if ($c == ':')
{
$f .= ': ';
}
else if ($c == ',')
{
$f .= ',';
$newline = true;
}
else
{
$f .= $c;
}
}
return $f;
}
}
Hi hope somone can help with this one. Ive had a birthday reminder app built, that aquires the usual permissions including offline access etc.
The app requires a daily cron job to be run on my server.
When I run the cron file a recieve the below error
Fatal error: Uncaught OAuthException: Invalid OAuth access token signature. thrown in blah/base_facebook.php on line 1140;
Is there a common reason for the error, am i doing anything wrong that stands out, and should i be displaying more code to get help from people?
below are the lines leading up to the error. My code ends on line 1140;
<?php
$name = 'api';
if (isset($READ_ONLY_CALLS[strtolower($method)])) {
$name = 'api_read';
} else if (strtolower($method) == 'video.upload') {
$name = 'api_video';
}
return self::getUrl($name, 'restserver.php');
}
protected function getUrl($name, $path='', $params=array())
{
$url = self::$DOMAIN_MAP[$name];
if ($path) {
if ($path[0] === '/') {
$path = substr($path, 1);
}
$url .= $path;
}
if ($params) {
$url .= '?' . http_build_query($params, null, '&');
}
return $url;
}
protected function getCurrentUrl() {
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
$currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parts = parse_url($currentUrl);
$query = '';
if (!empty($parts['query'])) {
// drop known fb params
$params = explode('&', $parts['query']);
$retained_params = array();
foreach ($params as $param) {
if ($this->shouldRetainParam($param)) {
$retained_params[] = $param;
}
}
if (!empty($retained_params)) {
$query = '?'.implode($retained_params, '&');
}
}
// use port if non default
$port =
isset($parts['port']) &&
(($protocol === 'http://' && $parts['port'] !== 80) ||
($protocol === 'https://' && $parts['port'] !== 443))
? ':' . $parts['port'] : '';
// rebuild
return $protocol . $parts['host'] . $port . $parts['path'] . $query;
}
protected function shouldRetainParam($param) {
foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) {
if (strpos($param, $drop_query_param.'=') === 0) {
return false;
}
}
return true;
}
protected function throwAPIException($result) {
$e = new FacebookApiException($result);
?>
CRON.php
<?php
require_once("src/facebook.php");
include("custom.php");
set_time_limit(0);
$config = array();
$config['array'] = $appID;
$config['secret'] = $appSecret;
$facebook = new Facebook($config);
$day = abs(date("j"));
$month = abs(date("n"));
$result = mysql_query("SELECT uid, uid2, name2 FROM birthdays WHERE birthmonth = '$month' AND birthday = '$day'");
while(($row = mysql_fetch_assoc($result)) && mysql_num_rows($result)) {
$link = $hostURL.'post.php?uid='.$row['uid'].'&uid2='.$row['uid2'];
$facebook->api('/'.$row['uid'].'/feed', 'POST',
array(
'link' => $link,
'from' => '299185790135651',
'picture' => $hostURL.'image.php?id='.$row['uid2'],
'name' => 'Send Cake',
'message' => 'It\'s '.$row['name2'].'\'s birthday today! Send them a virtual cake!',
'caption' => 'Sponsored by Intercake Ltd'
));
}
?>
also... what is 'from' => '299185790135651', ?
want to check my developer has put the right number here. Thanks
The best way to handle this is to use a try...catch statement. As follows:
try {
// some code that calls Facebook
} catch ( Exception $e ) {
// $e will contain the error - do what you want with it here
// e.g. log it or send an email alert etc.
}
The 'from' => '299185790135651' is a User / Page ID that publishes the message to the Feed. In this case, it's pointing to a Test Facebook Page.
I have a script with using a lot of Magic method __call.
The script have 15 000 iterance and the object is bigger.
After every iterance the memory grows. I use unset or $val = null; but the memory continues to grow.
What can i do?
An Exemple :
$data = null;
foreach ($field['method']['actions'] as $action) {
// si l'action ne concerne pas le name space principal
if (!array_key_exists('get', $action)) {
continue;
}
if (array_key_exists('begin', $action)) {
$data .= $action['begin'];
}
if (array_key_exists('action', $action)) {
$obj = $notice->__call('get' . ucfirst($action['action']));
$notice->clear();
if (is_object($obj)) {
$rsl = $obj->__call('get' . ucfirst($action['get']));
$obj->clear();
echo "\n" . 'get' . ucfirst($action['get']) . ' : ' . number_format(memory_get_usage());
$data .= $rsl;
unset($rsl);
} else {
$data .='';
}
$obj = null;
} else {
$data .= $notice->__call('get' . ucfirst($action['get']));
$notice->clear();
echo "\n" . 'get' . ucfirst($action['get']) . ' : ' . number_format(memory_get_usage());
}
if (array_key_exists('end', $action)) {
$data .= $action['end'];
}
}
//--
class Notice{
//--
protected $instanceObj = null;
public function __call($name, $arguments = null) {
$this->instanceObj = $this->$name($arguments);
return $this->instanceObj;
}
public function clear(){
$this->instanceObj = null;
}
//--
}
An exemple of log file :
getField : 24,446,752
getField : 24,447,352
getField : 24,447,720
getField : 24,448,096
getField : 24,483,320
getField : 24,483,336
getField : 24,483,728
...
getField : 25,267,936
...
getField : 35,596,712
...
You can see the memory never stop to brows.
The only solution is to sequence the script several execution. The problem is not PHP Symfony but generates too many objects. So I run the script Pacquet x. Otherwise it led to a saturation of memory.
I have a requirement to get the total no.of tweets, retweets and replies on a particular tag or user account. How to get these numbers efficiently? The numbers should be exact and not like 100+.
I also need to get the total no.of direct messages.
Using this site as a starting point I've been trying the same thing:
Pull Twitter feed into your site
<?php
require_once 'db-functions.inc.php' ; //custom database functions
function saveTweets($screen_name) {
global $link;
$screen_name = dbEscape(strtolower(trim($screen_name)));
if (!$screen_name) { echo "<p><strong>Error: No screen name declared.</strong></p>\n"; return false; }
$row = dbGetRow("SELECT `id` FROM `retweet` WHERE `screen_name`='$screen_name' ORDER BY `id` DESC LIMIT 1");
$last_id = $row['id'];
$url = "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=$screen_name&count=1500&include_rts=true" ;
if ($last_id) { $url .= "&since_id=$last_id" ; }
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, TRUE);
$xml = curl_exec ($ch);
curl_close ($ch);
$affected = 0;
$twelement = new SimpleXMLElement($xml);
foreach ($twelement->status as $status) {
$text = dbEscape(trim($status->text));
$time = strtotime($status->created_at);
$id = $status->id;
$retweet_count = $status->retweet_count;
dbQuery("INSERT INTO `twit` (`id`,`screen_name`,`time`,`text`,`hidden`,`retweet_count`) VALUES ('$id','$screen_name','$time','$text','n','$retweet_count')");
$affected = $affected + dbAffectedRows();
}
return "<p>".number_format($affected)." new tweets from $screen_name saved.</p>\n" ;
}
echo saveTweets('stackoverflow');
echo saveTweets('Apple');
echo saveTweets('Android');
echo saveTweets('Google');
?>
<h3>Stackoverflow</h3>
<?php
require_once 'databaseconnection.php' ; //database connection function
$result = dbQuery("SELECT * FROM `retweet` WHERE `hidden` != 'y' ORDER BY `retweet_count` DESC");
while ($row = mysql_fetch_array($result)) {
echo $row[0];
echo "<br>";
echo date("l, M j, Y, G:i a",$row[3]);
echo " : ";
echo stripslashes($row[2]);
echo "<br>";
echo stripslashes($row[4]);
echo "<br>Retweet: ";
echo stripslashes($row[6]);
echo "<br>";
echo "<br>";
}
?>
At the present time this doesn't have an "UPDATE" clause in it to take into account the retweet_count increasing, and you can remove:
return "<p>".number_format($affected)." new tweets from $screen_name saved.</p>\n" ;
If you don't need to see what has been updated.
Hope that helps