Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Multiple Edit Upload.

eugcar

The Saint
Advanced Member
Messages
880
Reaction score
0
Points
26
paki inspect yung codes ko kung anong errors? kapag nagrereupload kc me isang images lang ang naissave eh.

-serverside/product/product_multiple_edit.php
-product_multiple_edit.php code-
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
define('DOC_ROOT_PATH', $_SERVER['DOCUMENT_ROOT'].'/');
require DOC_ROOT_PATH . './db/db.php';
define('resize_width', 1024);
define('resize_height', 576);
define('thumb_width', 320);
define('thumb_height', 180);
$id = $_POST['chk'];
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
foreach($_FILES as $file)
{
// some information about image we need later.
$Image = $file['name'];
$ImageSize = $file['size'];
$TempSrc = $file['tmp_name'];
$ImageType = $file['type'];

if (is_array($Image))
{
$c = count($id);
/** loop through the array of files ***/
for($i=0; $i < $c; $i++)
{
// Number of uploaded files
$imageFolder = $_POST['imgFolder'];
$imageName = $_POST['imgName'];
$imageDetails = $_POST['imgDetails'];
$imagePrice = $_POST['imgPrice'];

$RandomNumber = rand(1, 9999999); // We need same random name for both files.
//Get file extension from Image name, this will be re-added after random name
$ImageExt = substr($Image[$i], strrpos($Image[$i], '.'));
$ImageExt = str_replace('.','',$ImageExt);

//Construct a new image name (with random number added) for our new image.
$imagePhoto = $RandomNumber.'.'.$ImageExt;

$dirpath = "../../images/". mysqli_real_escape_string($MySQLiconn, $imageFolder[$i]) ."/";
$dirthumb = $dirpath ."/thumb/";

//$OLDFile = basename($_REQUEST['OLDimgPhoto'][$i]);
//$OLDFileThumb = basename($_REQUEST['OLDimgThumb'][$i]);
//$OLDimagePhoto = $dirpath . $OLDFile;
//$OLDimageThumb = $dirthumb . $OLDFileThumb;

if(is_dir($dirpath) == false)
{
mkdir($dirpath, 0777, true) or die($MySQLiconn->error());
}

if(is_dir($dirthumb) == false)
{
mkdir($dirthumb, 0777, true) or die($MySQLiconn->error());
}

if(move_uploaded_file($TempSrc[$i], $dirpath. $imagePhoto))
{
$original = $imagePhoto;
$thumbnail = "thumbnail_" . $original;
$path_dir = $dirpath . $imagePhoto;
$thumb_dir = $dirthumb . "thumbnail_" . $imagePhoto;
$filename = $dirpath . $imagePhoto;
$resized = $dirpath . $imagePhoto;
$thumb = $dirthumb . "thumbnail_" . $imagePhoto;

$pic = $MySQLiconn->query("SELECT * From product as p
INNER JOIN product_images as pi
ON p.id = pi.product_id
WHERE p.id ='".$id[$i]."'");
while($rows= $pic->fetch_assoc()){
$ids = $rows['id'];
$product_folder = $rows['product_folder'];
$path_photo = "../../images/" . $product_folder . "/" . $rows['original_image'];
$path_thumb = "../../images/" . $product_folder . "/thumb/" . $rows['thumbnail_image'];
unlink($path_photo);
unlink($path_thumb);
}
$picdel = $MySQLiconn->query("DELETE FROM product_images WHERE product_id = '".$ids."'");

if (resizeImage($filename, resize_width, resize_height, $resized))
{
// Create a thumbnail image
if (!resizeImage($filename, thumb_width, thumb_height, $thumb))
{
echo "There was an error creating a thumbnail image.";
unlink($resized);
}
}
else
{
echo "There was an error resizing your image.";
}
$sql = "UPDATE product
SET
product_name = '".mysqli_real_escape_string($MySQLiconn, $imageName[$i])."',
product_details = '".mysqli_real_escape_string($MySQLiconn, $imageDetails[$i])."',
product_folder = '".mysqli_real_escape_string($MySQLiconn, $imageFolder[$i])."',
product_price = '".mysqli_real_escape_string($MySQLiconn, $imagePrice[$i])."',
product_date = '".date("Y-m-d H:i:s")."',
ip_address = '".$ip."'
WHERE
id='".$id[$i]."'";

$sql2 = "INSERT INTO product_images
(product_id, original_image, thumbnail_image)
VALUES
('".$ids."', '".$original."', '".$thumbnail."')";
$sql2 = $MySQLiconn->query($sql2);
$sql = $MySQLiconn->query($sql);
if($sql)
{
print_r($_POST);
?>
<script>
alert('<?php echo "Successfully inserted " . $c . " rows"; ?>');
window.location.href='/admin/product';
</script>
<?php
}else{
?>
<script>
alert('error while inserting , TRY AGAIN');
</script>
<?php
}
}else{

$nosql = $MySQLiconn->query("SELECT * From product as p
INNER JOIN product_images as pi
ON p.id = pi.product_id
WHERE p.id ='".mysqli_real_escape_string($MySQLiconn, $id[$i])."'");

while($rs = $nosql->fetch_assoc())
{
$product_folder = $rs['product_folder'];
$product_id = $rs['product_id'] ;
$imgPhoto = "../../images/" . $product_folder . "/" . $rs['original_image'];
$imgThumb = "../../images/" . $product_folder . "/thumb/" . $rs['thumbnail_image'];
rename($imgPhoto,$dirpath . $rs['original_image']);
rename($imgThumb,$dirthumb. $rs['thumbnail_image']);
}
$sqlNoPhoto = "UPDATE product
SET
product_name = '".mysqli_real_escape_string($MySQLiconn, $imageName[$i])."',
product_details = '".mysqli_real_escape_string($MySQLiconn, $imageDetails[$i])."',
product_folder = '".mysqli_real_escape_string($MySQLiconn, $imageFolder[$i])."',
product_price = '".mysqli_real_escape_string($MySQLiconn, $imagePrice[$i])."',
product_date = '".date("Y-m-d H:i:s")."',
ip_address = '".$ip."'
WHERE
id='".$id[$i]."'";


$renp = $MySQLiconn->query($sqlNoPhoto);
if($renp)
{
?>
<script type="text/javascript">
alert("Successfully! Updated...");
window.location.href='/admin/product';
</script>
<?php
}else{
echo '<div class="error">Error occurred while trying to process <strong>'.$ImageName[$i].'</strong>, may be file too big!</div>'; //output error
}
}
}
}
}

// image resize and create thumbnails
function resizeImage($filename, $max_width, $max_height, $newfilename="", $withSampling=true)
{
$width = 0;
$height = 0;

$newwidth = 0;
$newheight = 0;

// If no new filename was specified then use the original filename
if($newfilename == "")
{
$newfilename = $filename;
}

// Get original sizes
list($width, $height) = getimagesize($filename);

if ($width > $height)
{
// We're dealing with max_width
if ($width > $max_width)
{
$newwidth = $width * ($max_width / $width);
$newheight = $height * ($max_width / $width);
}
else
{
// No need to resize
$newwidth = $width;
$newheight = $height;
}
}
else
{
// Deal with max_height
if ($height > $max_height)
{
$newwidth = $width * ($max_height / $height);
$newheight = $height * ($max_height / $height);
}
else
{
// No need to resize
$newwidth = $width;
$newheight = $height;
}
}

// Create a new image object
$thumb = imagecreatetruecolor($newwidth, $newheight);

// Load the original based on it's extension
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));

if($ext=='jpg' || $ext=='jpeg')
{
$source = imagecreatefromjpeg($filename);
}
else if($ext=='gif')
{
$source = imagecreatefromgif($filename);
}
else if($ext=='png')
{
$source = imagecreatefrompng($filename);
}
else
{
// Fail because we only do JPG, JPEG, GIF and PNG
return FALSE;
}

// Resize the image with sampling if specified
if($withSampling)
{
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
else
{
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}

// Save the new image
if($ext=='jpg' || $ext=='jpeg')
{
return imagejpeg($thumb, $newfilename);
}
else if($ext=='gif')
{
return imagegif($thumb, $newfilename);
}
else if($ext=='png')
{
return imagepng($thumb, $newfilename);
}

imagedestroy($thumb);
imagedestroy($newfilename);
}
?>

-admin/product/product_multiple_edit.php
-product_multiple_edit.php code-
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
define('DOC_ROOT_PATH', $_SERVER['DOCUMENT_ROOT'].'/');
require DOC_ROOT_PATH . './db/db.php';
require DOC_ROOT_PATH . './apps/admin/user-account.php';

if(isset($_POST['chk'])=="")
{
?>
<script>
alert('At least one checkbox Must be Selected !!!');
window.location.href='index.php';
</script>
<?php
}
$chk = $_POST['chk'];
$chkcount = count($chk);

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Product Multiple Edit</title>
</head>
<body>
<form name='fileupload' role="form" id="fileupload" method="post" action="<?php echo $egsmembersite->base_url(); ?>serverside/product/product_multiple_edit.php" enctype="multipart/form-data">
<?php
for($i=0; $i<$chkcount; $i++)
{
$id = $chk[$i];

$res = $MySQLiconn->query("SELECT * From product as p
INNER JOIN product_images as pi
ON p.id = pi.product_id
WHERE p.id='$id'
GROUP BY p.id
ORDER BY p.product_name ASC");
while($runrows = $res->fetch_assoc())
{
$id = $runrows['id'];

$imageName = $runrows['product_name'];
$imageFolder = $runrows['product_folder'];
$imageDetails = nl2br($runrows['product_details']);
$imagePrice = $runrows['product_price'];

$dirpath = "../../images/".$imageFolder."/";
$dirthumb = $dirpath . "thumb/";
$imagePhoto = $dirpath . $runrows['original_image'];
$imageThumb = $dirthumb . $runrows['thumbnail_image'];
?>


<div class="control-group form-group">
<div class="controls">
<input type="hidden" name="chk[]" value="<?php echo $id; ?>">
<input type="file" class="file" id="images" multiple name="images[]" data-overwrite-initial="false">
</div>
</div>

<div class="row">
<div class="col-md-8">
<div class="control-group form-group">
<div class="controls">
<label class="control-label" for="imgName">
<i class="glyphicon glyphicon-picture"></i> Product Name
</label>
<input type="text" class="form-control" name="imgName[]" value="<?php echo $imageName; ?>" placeholder="Name">
</div>
</div>
</div>

<div class="col-md-4">
<div class="control-group form-group">
<div class="controls">
<label class="control-label" for="imgPrice">
<i class="glyphicon glyphicon-usd"></i> Product Price
</label>
<input type="text" class="form-control" name="imgPrice[]" value="<?php echo $imagePrice; ?>" placeholder="Price">
</div>
</div>
</div>
</div>

<div class="control-group form-group">
<div class="controls">
<label class="control-label" for="imgFolder">
<i class="glyphicon glyphicon-list-alt"></i> Choose Folder
</label>
<select class="form-control" name="imgFolder[]" id="imgFolder">
<option value="<?php echo $imageFolder; ?>" selected="selected"><?php echo $imageFolder; ?></option>
<optgroup label="-- Bluetooth & Wireless Categories --">
<option value="Bluetooth Headset & Speaker">Bluetooth Headset & Speaker</option>
<option value="Bluetooth Keyboard & Mouse">Bluetooth Keyboard & Mouse</option>
<option value="Bluetooth USB Dungle & Receiver">Bluetooth USB Dungle & Receiver</option>
</optgroup>

<div class="control-group form-group">
<div class="controls">
<label class="control-label" for="imgDetails">
<i class="glyphicon glyphicon-info-sign"></i> Product Details
</label>
<textarea class="form-control" name="imgDetails[]" rows="6" wrap="off" placeholder="Details"><?php echo strip_tags($imageDetails, '<p><a>'); ?></textarea>

</div>
</div>
<?php
}
}
?>
<div id="success"></div>
<!-- For success/fail messages -->
<div class="control-group form-group">
<div class="controls text-right">
<button type="submit" id="productSubmit" name="productSubmit" class="btn btn-success">
<i class="glyphicon glyphicon-save"></i> Submit
</button>
<button type="button" class="btn btn-warning" onclick="window.location.href='index'">
<i class="glyphicon glyphicon-backward"></i> Cancel
</button>
<span id="loading" class='text-left'></span>
</div>
</div>
</form>
<div class="progress">
<div class="progress-bar progress-bar-striped"></div >
<div class="percent"></div >
</div>

<div id="status"></div>
</div>
</div>
</div><!-- /.end panel-body -->
</div><!-- /.end panel -->
</div><!-- /.end row -->
</div><!-- /end page -->

<?php require DOC_ROOT_PATH . './apps/dashboard/js/ckeditor_script.php'; ?>
<?php require DOC_ROOT_PATH . './apps/public/js/jqueryform_script.php'; ?>
<script>
function CKupdate(){
for ( instance in CKEDITOR.instances ){
CKEDITOR.instances[instance].updateElement();
}
}
(function(document, window, $) {
var editor = $('textarea').ckeditor({
toolbar: 'Full',
enterMode : CKEDITOR.ENTER_BR,
shiftEnterMode: CKEDITOR.ENTER_P
});
editor.on( 'change', function( evt ) {
// getData() returns CKEditor's HTML content.
console.log( 'Total bytes: ' + evt.editor.getData().length );
});
$('document').ready(function(){
var bar = $('.progress-bar');
var percent = $('.percent');
var status = $('#status');
var loading = $('#loading');
$('form').ajaxForm({
beforeSend:function(){
loading.show();
status.empty();
var percentVal = '0%';
bar.width(percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal)
percent.html(percentVal);
//console.log(percentVal, position, total);
},
success: function() {
$('#success').html("<div class='alert alert-success'>");
$('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-success')
.append("<strong>Your Submitted Record is Successfully Updated!</strong>");
$('#success > .alert-success')
.append('</div>');
var percentVal = '100%';
bar.width(percentVal)
percent.html(percentVal);
loading.hide();
CKupdate();
},
error: function(jqXHR, textStatus, errorThrown) {
loading.hide();
$('#success').html("<div class='alert alert-danger'>");
$('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
.append("</button>");
$('#success > .alert-danger').append("<strong>Sorry! Your Submitted Record is Failed! Please try again...");
$('#success > .alert-danger').append('</div>');
},
complete: function(xhr) {
loading.hide();
status.empty();
var percentVal = '';
bar.width(percentVal)
percent.html(percentVal);
}
});
});
})(document, window, jQuery);
</script>
</body>

</html>

- - - Updated - - -

-- product --
View attachment 259476
View attachment 259477

-- multiple edit --
View attachment 259478
View attachment 259479
View attachment 259480
View attachment 259481
 

Attachments

  • add product.jpg
    add product.jpg
    188.9 KB · Views: 11
  • add product_results.jpg
    add product_results.jpg
    179.6 KB · Views: 3
  • multiple edit.jpg
    multiple edit.jpg
    177.1 KB · Views: 9
  • multiple edit 10images.jpg
    multiple edit 10images.jpg
    235.7 KB · Views: 3
  • multiple edit submit.jpg
    multiple edit submit.jpg
    164.3 KB · Views: 1
  • multiple edit result.jpg
    multiple edit result.jpg
    163.7 KB · Views: 2
itry mo lagi i-run muna yung pinaka-basic function ng file upload, kapag gumana na, tsaka mo unti-unting i-incorporate sa ginagawa mo. subukan mo muna itong sample code, may attribute na multiple yung file input mo, then may "[]" yung name nung file input para ma-retrieve sya as array.

dun sa may dulo ng php script ko may mapapansin ka na foreach loop, yung $key ang gamitin mo para maretrieve mo yung iba values sa loob nung $_FILES array, check mo output nya para magka-idea ka how to traverse the array

Code:
<!DOCTYPE html>
<html>
<body>

<form method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload[]" id="fileToUpload" multiple>
    <input type="submit" value="Upload Image" name="submit">
	<input type="hidden" name="submitted" />
</form>

</body>
</html>

<?php
	if(isset($_POST['submitted'])){
		
		echo '<pre>';
			print_r($_FILES);
		echo '</pre>';
		
		foreach($_FILES['fileToUpload']['name'] as $key=>$value){
			echo $key . ' - ' . $value . '<br>';
		}
		
	}
?>
 
n k count id po ako sir jzkhulitz.

kpag ganito naman ang ginamit ko.

foreach($_FILES as $file)
{
// some information about image we need later.
$Image = $file['name'];
$ImageSize = $file['size'];
$TempSrc = $file['tmp_name'];
$ImageType = $file['type'];

if (is_array($Image))
{
$c = count($Image);
/** loop through the array of files ***/
for($i=0; $i < $c; $i++)
{

actually na sstore naman yung images sa images folder yun nga lang hindi na naiistore ng maaus yung data sa database.
nagiging 0 yung product_id. upload ko po para sa live demo

- - - Updated - - -

demo site: http://www.mypos.16mb.com
demo user: demo
demo pass: 12345678
 
anong pwedeng gamitin? in_array()?

na ka count(Image)

actually napasok naman ang images file. yun ngal ang napupunta nga lang sya sa images/???.jpg at images/thumb/???.jpg

hindi sya napupunta sya images/destination folder/???.jpg at images/destination folder/thumb/???.jpg

and then yung product_id is nagiging 0.
 
Back
Top Bottom