Re: [MOD]Rapid Image Uploader (image manager alternative)
Posted: Mon May 02, 2011 7:07 pm
OpenCart Community Forum - Discuss shopping cart and e-commerce solutions.
https://forum.opencart.com/
Code: Select all
$uploads_dir = "../../../image/data/";
Code: Select all
$image_dir = "../../../image/data/";
$cache_dir = "../../../image/cache/data/";
Code: Select all
$uploads_dir = "../../../image/data/produtos/";
Code: Select all
$image_dir = "../../../image/data/produtos/";
$cache_dir = "../../../image/cache/data/produtos/";
Code: Select all
html += '<td class="left"><input type="hidden" name="product_image[' + image_row + ']" value="data/' + image_name +'" id="image' + image_row + '" /><img src="<?php echo $image_path; ?>' + 'cache/data/' + im_thumb + '" alt="" id="preview' + image_row + '" class="image" onclick="image_upload(\'image' + image_row + '\', \'preview' + image_row + '\');" /></td>';
html += '<td class="left"><input type="radio" name="image" value="data/' + image_name +'" id="image" /></td>'
Code: Select all
html += '<td class="left"><input type="hidden" name="product_image[' + image_row + ']" value="data/produtos/' + image_name +'" id="image' + image_row + '" /><img src="<?php echo $image_path; ?>' + 'cache/data/produtos/' + im_thumb + '" alt="" id="preview' + image_row + '" class="image" onclick="image_upload(\'image' + image_row + '\', \'preview' + image_row + '\');" /></td>';
html += '<td class="left"><input type="radio" name="image" value="data/produtos/' + image_name +'" id="image" /></td>'
Code: Select all
<?php
$uploads_dir = "../../../image/data/";
$produts_dir = "produtos/";///// changes //////////////////////////////
$uploads_dir = $uploads_dir . $produts_dir;///// changes ////////////////////////////
$myFiles = array();
if(count($_FILES["Filedata"]["error"]) < 2) {
// Single file
$tmp_name = $_FILES["Filedata"]["tmp_name"];
$name = $_FILES["Filedata"]["name"];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
} else {
// Multiple files
foreach ($_FILES["Filedata"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["Filedata"]["tmp_name"][$key];
$name = $_FILES["Filedata"]["name"][$key];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
}
}
//echo 'RETURN DATA!';
echo implode(';', $myFiles);
function resize($filename, $width, $height)
{
require_once('../../../system/library/image.php');
$image_dir = "../../../image/data/";
$cache_dir = "../../../image/cache/data/";
$image_dir = $image_dir . $produts_dir;///// changes /////////////////////////////
$cache_dir = $cache_dir . $produts_dir;///// changes ///////////////////////
$info = pathinfo($filename);
$extension = $info['extension'];
$new_image = substr($info['filename'], 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
///// changes ///////////////////////////
$tempPath = substr($info['dirname'], strlen($image_dir));
$tempPathName = $tempPath . '/' . $info['basename'];
if (file_exists($image_dir . $info['basename']))
{
$myimage = new Image($image_dir . $info['basename']);
$myimage->resize($width, $height);
$myimage->save($cache_dir . $new_image);
}
//return $info['basename'];
return $tempPathName;///// changes ///////////////////////////////
}
?>
Code: Select all
$myimage->save($cache_dir . $new_image);
Code: Select all
return $info['basename'];
Code: Select all
return $tempPathName;///// changes ///////////////////////////////
Code: Select all
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
Code: Select all
if (file_exists($image_dir . $info['basename']))
{
$myimage = new Image($image_dir . $info['basename']);
$myimage->resize($width, $height);
$myimage->save($cache_dir . $new_image);
}
Code: Select all
$uploads_dir = "../../../image/data/";
$produts_dir = "produtos/";
$uploads_dir = $uploads_dir . $produts_dir;
...
$image_dir = "../../../image/data/" . $produts_dir;
$cache_dir = "../../../image/cache/data/" . $produts_dir;
Code: Select all
$uploads_dir = "../../../image/data/produtos/";
...
$image_dir = "../../../image/data/produtos/";
$cache_dir = "../../../image/cache/data/produtos/" ;
Code: Select all
<?php
$uploads_dir = "../../../image/data/produtos/";
$myFiles = array();
if(count($_FILES["Filedata"]["error"]) < 2)
{
// Single file
$tmp_name = $_FILES["Filedata"]["tmp_name"];
$name = $_FILES["Filedata"]["name"];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
else
{
// Multiple files
foreach ($_FILES["Filedata"]["error"] as $key => $error)
{
if ($error == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["Filedata"]["tmp_name"][$key];
$name = $_FILES["Filedata"]["name"][$key];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext)) {
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
}
}
//echo 'RETURN DATA!';
echo implode(';', $myFiles);
function resize($filename, $width, $height)
{
require_once('../../../system/library/image.php');
$image_dir = "../../../image/data/produtos/";
$cache_dir = "../../../image/cache/data/produtos/";
$info = pathinfo($filename);
$extension = $info['extension'];
$new_image = substr($info['filename'], 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
$tempPathName = "produtos/" . $info['basename'];
if (file_exists($image_dir . $info['basename']))
{
$myimage = new Image($image_dir . $info['basename']);
$myimage->resize($width, $height);
$myimage->save($cache_dir . $new_image);
}
//return $info['basename'];
return $tempPathName;///// changes ////////////////////}
?>
Code: Select all
<?php
$productDir = 'products/';
$uploads_dir = '../../../image/data/' . $productDir;
$myFiles = array();
if(count($_FILES["Filedata"]["error"]) < 2)
{
// Single file
$tmp_name = $_FILES["Filedata"]["tmp_name"];
$name = $_FILES["Filedata"]["name"];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext))
{
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
else
{
// Multiple files
foreach ($_FILES["Filedata"]["error"] as $key => $error)
{
if ($error == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["Filedata"]["tmp_name"][$key];
$name = $_FILES["Filedata"]["name"][$key];
$ext = substr(strrchr($name, '.'), 1);
switch(strtolower($ext))
{
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'png':
case 'doc':
case 'txt':
move_uploaded_file($tmp_name, "$uploads_dir/$name");
break;
default:
exit();
break;
}
array_push($myFiles, resize($uploads_dir.$name, 100, 100));
}
}
}
//echo 'RETURN DATA!';
echo implode(';', $myFiles);
function resize($filename, $width, $height)
{
require_once('../../../system/library/image.php');
global $productDir;
$image_dir = '../../../image/data/' . $productDir;
$cache_dir = '../../../image/cache/data/' . $productDir;
$info = pathinfo($filename);
$extension = $info['extension'];
$new_image = substr($info['filename'], 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if(!file_exists($cache_dir))
{
mkdir($cache_dir );
}
if (file_exists($image_dir . $info['basename']))
{
$myimage = new Image($image_dir . $info['basename']);
$myimage->resize($width, $height);
$myimage->save($cache_dir . $new_image);
}
$tempPathName = $productDir . $info['basename'];
return $tempPathName;
}
?>
gsk wrote:Hi,
I will probably make it a vqmod, so you could apply it to all 1.5.x revisions.
Probably next week, if I manage to get some free time.