Uploadify 3.2.1 says file uploaded but can't see it - uploadify

I've searched on many posts to solve my problem, tried many things and it didn't worked for me. The problem is that I try to upload a file with the demo page provided by the Uploadify plugin (v3.2.1) and it says that the download is complete, but I can't see the file on the server.
First, let's say that I've modified php.ini in my public_html folder to set a path to upload_tmp_dir and session.savepath. I've set both to this : /home/ensembl/public_html/accp/uploadTemp
Then, in the public_html folder again, I've created the .htaccess file and wrote this line into it : suPHP_ConfigPath /home/ensembl/public_html/ to apply the change to all files and subfolders.
All folders have 0755 permissions and all files have 0644.
Is someone seeing what's wrong?
There it goes the code I have now :
index.php
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>UploadiFive Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="uploadify.css">
<style type="text/css">
body {
font: 13px Arial, Helvetica, Sans-serif;
}
</style>
</head>
<body>
<h1>Uploadify Demo <?php
//The following line is just to show the paths
echo $_SERVER['DOCUMENT_ROOT'].'/downloadsUploadify/'.'<br/>'.sys_get_temp_dir().' | '.ini_get('upload_tmp_dir');?></h1>
<form>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true">
</form>
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : 'uploadify.php',
'fileSizeLimit' : '20MB',
'fileTypeExts' : '*.jpg; *.jpeg; *.gif; *.png; *.mp3; *.pdf; *.txt',
'removeTimeout' : 60,
'removeCompleted' : false,
'requeueErrors' : true,
'onUploadComplete' : function(file) { alert('The file ' + file.name + ' finished processing.'); },
'onUploadError' : function(file, errorCode, errorMsg, errorString) { alert('The file ' + file.name + ' could not be uploaded: ' + errorString); },
'onUploadSuccess' : function(file, data, response) { alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data); }
});
});
</script>
</body>
</html>
Result of sys_get_temp_dir() => /tmp
Result of ini_get('upload_tmp_dir') => /home/ensembl/public_html/accp/uploadTemp
uploadify.php
<?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
// Define a destination
$targetFolder = '/downloadsUploadify/'; // Relative to the root
$verifyToken = md5('unique_salt' . $_POST['timestamp']);
if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png','mp3', 'pdf', 'txt'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
?>
check-exists.php
<?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
// Define a destination
$targetFolder = '/downloadsUploadify/'; // Relative to the root and should match the upload folder in the uploader script
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $targetFolder . '/' . $_POST['filename'])) {
echo 1;
} else {
echo 0;
}
?>

In index.php in <script> <?php $timestamp = time();?>, and within the function uploadify, you should add the following:
'FormData' : {
'timestamp': '<? php echo $ timestamp;>',
'token': '<? php echo md5 (' unique_salt '$ timestamp.)>'
},
documentation
The TargetFolder must use the direct address to the folder that stores the images example:
/5/uploadify/archivos /

Related

WooCommerce related products - Load more (ajax)

I have a WooCommerce store where we need to have a lot of related products. We wish to only show 4 to begin with and then a "Show more" function. I would prefer not just to hide the products and then show with jQuery, but have them loaded dynamically with ajax.
I have searched for similar solution, but can't find anything. So I am hoping there are some out there that can help me?
And for the index.php file:
<?php
include 'dbh.php';
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="index.js"></script>
<script src="jquery-3.5.1.min.js"></script>
</head>
<body>
<div id="products">
<?php
$sql = "SELECT * FROM products LIMIT 2";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)) {
echo "<p>";
echo $row['product'];
echo "<br>";
echo $row['product_name'];
echo "</p>";
}
} else {
echo "There are no more products.";
}
?>
</div>
<button id="btn">Show more products</button>
</body>
</html>
<!-- language: lang-js -->
$(document).ready(function(){
var productCount = 2;
$("btn").click(function() {
productCount += 2;
$("#data-placeholder").load("loaded_data.php", {
productNewCount: productCount
});
});
});
<!-- end snippet -->
enter code hereYou need to to use multiple files in Ajax, one where the data loads that you can call loaded_data.php that is going to to get added to the main php file (example: index.php),
<?php
include 'dbh.php';//dbh.php is the file that hold the database connection.
$productNewCount = $POST['productNewCount'];
$sql = "SELECT * FROM products LIMIT $productNewCount";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)) {
echo "<p>";
echo $row['product_name'];
echo "<br>";
echo $row['product'];
echo "</p>";
}
} else {
echo "There are no more products!";
}
?>

PHP OpenDir - Need to sort results

I want to display a directory that contains only PDF's. I'd like the user to click on a given line and have the appropriate PDF displayed. I copied some code from this site and had to modify it. I put the "breaking return" tag so that each file would be displayed on a separate line. The following code works fine, but I need the file listings to be sorted alphabetically. I've tried the sort function for $thelist in several places, but I can't seem to get it to work. I appreciate your help.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
if ($handle = opendir('hymn_lyrics')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$thelist .= ''.$file.''.'<br />';
}
}
closedir($handle);
}
?>
<P>List of Hymns:</p>
<P><?=$thelist?></p>
</body>
</html>
I changed the code after reading another post here. This works fine:
<?php
$files = glob('hymn_lyrics/*.pdf', GLOB_BRACE);
foreach($files as $file)
{
if ($file != "." && $file != "..")
{
$thelist .= ''.$file.'<br />';
}
}
?>
<p>List of files:</p>
<p><?=$thelist?></p>

uncaught exception: Call to StartUpload failed in uploadify integration with codeigniter

i have integrated uploadify with codeigniter.i can't able select images while clicking the select photos.
MY View file
<!DOCTYPE HTML>
<html lang="en-GB">
<head>
<meta charset="UTF-8">
<title>Uploadify V3 & CodeIgniter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Capsone-System2" >
<!-- Styles -->
<link href="/assets/bootstrap/css/bootstrap.min.css" type="text/css" media="screen" rel="stylesheet"/>
<link href="<?php echo base_url;?>assets/js/jquery/uploadify_31/uploadify.css" type="text/css" media="screen" rel="stylesheet"/>
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<!-- Main Content -->
<div class="container">
<h1 class="page-header">Uploadify V3 & CodeIgniter</h1>
<p>This is a simple tutorial demo showing Uploadify V3 working with CodeIgniter 2.1.2</p>
<?php echo form_open_multipart(); ?>
<ul class="unstyled">
<li>
<?php echo form_upload('userfile','','id="userfile"'); ?>
<?php echo (isset($error)) ? $error : ''; ?>
</li>
<li>
<?php echo form_button(array('content'=> 'Upload', 'id'=>'upload-file', 'class'=>'btn btn-large btn-primary')); ?>
</li>
</ul>
<?php echo form_close(); ?>
</div>
<!-- End Of Main Content -->
<!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>-->
<!--<script>window.jQuery || document.write('<script src="<?php echo base_url;?>assets/js/jquery/jquery-1.8.0.min.js"></script>')</script>-->
<script src="<?php echo base_url;?>assets/js/jquery/uploadify_31/jquery.uploadify-3.1.min.js" type="text/javascript"></script>
<!--<script src="<?php echo base_url;?>assets/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>-->
<script type="text/javascript">
$(document).ready(function () {
var base_url = '<?php echo base_url; ?>';
alert(base_url);
$('#upload-file').click(function (e) {
e.preventDefault();
$('#userfile').uploadify('upload', '*');
alert(base_url);
});
$('#userfile').uploadify({
'debug':true,
'auto':false,
'swf': base_url + 'assets/js/jquery/uploadify_31/uploadify.swf',
'uploader': base_url + 'uploadify_v3/do_upload',
'cancelImg': base_url + 'assets/javascript/jquery/uploadify_31/uploadify-cancel.png',
'fileTypeExts':'*.jpg;*.bmp;*.png;*.tif',
'fileTypeDesc':'Image Files (.jpg,.bmp,.png,.tif)',
'fileSizeLimit':'2MB',
'fileObjName':'userfile',
'buttonText':'Select Photo(s)',
'multi':true,
'removeCompleted':false,
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
}
});
});
</script>
</body>
</html>
My Controller File
I have error uncaught exception: Call to StartUpload failed
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* #property CI_Upload $upload
*/
class Uploadify_v3 extends CI_Controller
{
public $view_data = array();
private $upload_config;
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->helper(array('url', 'form'));
$this->load->view('uploadify_v3', $this->view_data);
}
public function do_upload()
{
$this->load->library('upload');
$image_upload_folder = FCPATH . '/uploads';
if (!file_exists($image_upload_folder)) {
mkdir($image_upload_folder, DIR_WRITE_MODE, true);
}
$this->upload_config = array(
'upload_path' => $image_upload_folder,
'allowed_types' => 'png|jpg|jpeg|bmp|tiff',
'max_size' => 2048,
'remove_space' => TRUE,
'encrypt_name' => TRUE,
);
$this->upload->initialize($this->upload_config);
if (!$this->upload->do_upload()) {
$upload_error = $this->upload->display_errors();
echo json_encode($upload_error);
} else {
$file_info = $this->upload->data();
echo json_encode($file_info);
}
}
}
/* End of file uploadify_v3.php */
/* Location: ./application/controllers/uploadify_v3.php */
I have spent more time..still now i can't fix this error..please help me.
I too had the same problem, it was a security issue because I was hosting the flash .swf file on a separate domain eg: static.mysite.com
Make sure your swf file and post handler script are hosted on the same domain that you are accessing the site from.
Or if you need to add cross domain posting then see here:
http://www.adobe.com/devnet/adobe-media-server/articles/cross-domain-xml-for-streaming.html

jQuery UI is not inherited in ajax loaded content

I am using CI 2.1.3, having problem with jQuery UI inheritance. Trying to create a ajax gui sortable page nesting.
view/admin/components/page_head.php
<!DOCTYPE html>
<html>
<head>
<title><?php echo $meta_title; ?></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="<?=site_url(config_item('path_bootstrap').'css/bootstrap.min.css');?>" rel="stylesheet" media="screen">
<!-- jQuery -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
if (!window.jQuery) {
document.write('<script src="<?php echo site_url(config_item("path_assets")."js/jquery-1.10.1.js"); ?>"><\/script>');
}
</script>
<script src="<?php echo site_url(config_item('path_bootstrap').'js/bootstrap.min.js'); ?>"></script>
<?php //if((isset($sortable)) AND ($sortable === TRUE)): ?>
<!-- script src="<?php echo site_url(config_item('path_jqueryui').'minified/jquery-ui.min.js'); ?>"></script -->
<script src="<?php echo site_url(config_item('path_assets').'js/jquery-ui.js'); ?>"></script>
<script src="<?php echo site_url(config_item('path_assets').'js/jquery.mjs.nestedSortable.js'); ?>"></script>
<script type="text/javascript">
if (window.jQuery.ui) {
alert('jquery ui found');
}
else {
alert('jquery ui not found');
}
/*if (window.jQuery) {
alert('jquery found');
}
if (window.jQuery.ui) {
alert('jquery ui found');
}
if (window.jQuery.ui.sortable) {
alert('jquery ui sortable found');
}
if (window.jQuery.mjs.nestedSortable) {
alert('jquery nestedSortable found');
}*/
</script>
<?php //endif; ?>
<script src="<?php echo site_url(config_item('path_assets').'js/tinymce/tinymce.min.js'); ?>"></script>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
</head>
view/admin/order.php
<section>
<h2>Order pages</h2>
<p class="alert alert-info">Drag to order pages and then click 'Save'</p>
<div id="orderResult"></div>
<input type="button" id="save" value="Save" class="btn btn-primary" />
</section>
<?php dump($sortable); ?>
<script>
$(function() {
$.post('<?php echo site_url("tutsplus_admin/page/order_ajax"); ?>', {}, function(data)
{
$('#orderResult').html(data);
});
$('#save').click(function()
{
oSortable = $('.sortable').nestedSortable('toArray');
$('#orderResult').slideUp(function()
{
$.post('<?php echo site_url("tutsplus_admin/page/order_ajax"); ?>', { sortable: oSortable }, function(data)
{
$('#orderResult').html(data);
$('#orderResult').slideDown();
});
});
});
});
</script>
order_ajax.php
<?php
//dump($pages);
function get_ol ($array, $child = FALSE)
{
$str = '';
if (count($array)) {
$str .= $child == FALSE ? '<ol class="sortable">' : '<ol>';
foreach ($array as $item) {
$str .= '<li id="list_' . $item['id'] .'">';
$str .= '<div>' . $item['title'] .'</div>';
// Do we have any children?
if (isset($item['children']) && count($item['children'])) {
$str .= get_ol($item['children'], TRUE);
}
$str .= '</li>' . PHP_EOL;
}
$str .= '</ol>' . PHP_EOL;
}
return $str;
}
?>
<?php echo get_ol($pages); ?>
<script type="text/javascript">
$(document).ready(function()
{
$('.sortable').nestedSortable({
handle: 'div',
items: 'li',
toleranceElement: '> div',
maxLevels: 2
});
});
</script>
In order.php jquery, jquery_ui and msj.nestedSortable is succesfully loaded. order_ajax.php is loaded as ajax content. It is not working unless I load jquery ui and msj.nestedSortable script again in order_ajax.php.
Any thoughts?
Script content in a page loaded via AJAX is not beeing executed. Put your script in a *.js-File and load this via jQuery.getScript or change dataType of your AJAX call to script:
$.ajax({
...
dataType: "script",
...
});
From http://api.jquery.com/jQuery.ajax/:
dataType (default: Intelligent Guess (xml, json, script, or html))
Type: String
The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string).

How can I get current URL using smarty

How to get URL using Smarty similar to window.location in JavaScript ?
I did this
{$smarty.server.PHP_SELF}
but it's not working.
You can use this, too.
{$smarty.server.HTTP_HOST}{$smarty.server.REQUEST_URI}
See what is available with this:
{$smarty.server|#var_dump}
A couple examples for url https://some.example.com/some/path?param=1:
{$smarty.server.SCRIPT_URI}
https://some.example.com/some/path
{$smarty.server.SERVER_NAME}
some.example.com
{$smarty.server.SCRIPT_URL}
/some/path
This is controller code :
<?php
require_once('libs/Smarty.class.php');
$smarty = new Smarty();
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
$pro = 'https';
} else {
$pro = 'http';
}
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
$current_url = $pro."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
$smarty->assign("current_url",$current_url);
$smarty->display('index.tpl');
?>
You can display variable in index.tpl template file :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Title</title>
</head>
<body>
{$current_url}
</body>
</html>

Resources