Hello,
I am looking for a free script to upload image / moving image files to a certain folder and basically a database for cms image gallery.
Any free script like that ?
Hello,
I am looking for a free script to upload image / moving image files to a certain folder and basically a database for cms image gallery.
Any free script like that ?
Pick any good php framework... I like codeigniter because it makes uploading amongst other things really simple, laravel is also quite good.
ok, I think I find part of what I need. Now I have another question. Check this code:
input_image.php
<!-- begin form -->
<form action="upload.php" method="post" name="image_upload" id="image_upload" enctype="multipart/form-data">
<!-- begin addition -->
Location:
<select>
<option value="slide1">slide1</option>
<option value="slide2">slide2</option>
<option value="slide3">slide3</option>
<option value="other">other</option>
</select> <br><br>
<!-- end addition -->
<!-- begin image label and input -->
<label>Image (gif, jpg, png)</label><br />
<input type="file" size="45" name="uploadfile" id="uploadfile" class="file margin_5_0" onchange="ajaxUpload(this.form);" /><!-- end image label and input -->
<br />
<input name="4_images" type="checkbox" value="" /> <label>Create 4 images</label><br />
<label>Thumbnail / Big Image</label><br />
<!-- begin display uploaded image -->
<div id="upload_area" class="corners align_center">
please select image
</div><!-- begin display uploaded image -->
</form><!-- end form -->
</div><!-- end content -->
</body>
<!-- end extra -->
<?php include('adminnav.php'); ?>
<div id="menu">
<center>
<h2>Image Manager</h2>
</center>
<p> </p>
<p>metode image managementnya masih konstruksi</p><center>
<p>
<?php
include('../includes/koneksi.php');
?>
<?php
//LOAD IMAGE TABLE
$result = mysql_query("SELECT * FROM image_upload ORDER BY id") or die(mysql_error());
?>
<table id="admintable" border="1" cellpadding="2" cellspacing="0">
<tr>
<th>image</th><th>location</th><th>Post</th>
</tr>
<?php
$i=0;
while ($data = mysql_fetch_array($result)){
$result2=($i%2)?'#DFA09D':'white';
//echo "<tr bgcolor='$result2'>";
//echo '<td>'.$data['page'].'</td>';
//echo "<td><a href='post.php?post_id=".$data['post_ID']."'><img src='../images/post.jpg'></a></td>";
//echo '</tr>';
echo "<tr bgcolor='$result2'>";
echo '<td><a href="input_berita_static.php?post_id='.$data['id'].'">'.$data['image'].'</a></td>';
echo '<td>location</td>';
echo '<td>Centang</td>';
echo '</tr>';
$i++;
}
?>
</table>
My point is I have many different image sizes in different web location that I need to input. Is it possible to say:
if location = slide 1 then run upload1.php (action form)
else if location = other1 then run upload2.php (action form)
else run upload3.php
in each action form I will define the minimum and maximum image size and width.
How to organize the code (I already figure the upload image code, now I just need to define and image location and size variety.
I mean there is another logic that works better:
input_image.php
<!-- begin form -->
<form action="upload.php" method="post" name="image_upload" id="image_upload" enctype="multipart/form-data">
<!-- begin addition -->
Location:
<select>
<option value="slide1">slide1</option>
<option value="slide2">slide2</option>
<option value="slide3">slide3</option>
<option value="other">other</option>
</select> <br><br>
<!-- end addition -->
<!-- begin image label and input -->
<label>Image (gif, jpg, png)</label><br />
<input type="file" size="45" name="uploadfile" id="uploadfile" class="file margin_5_0" onchange="ajaxUpload(this.form);" /><!-- end image label and input -->
<br />
<input name="4_images" type="checkbox" value="" /> <label>Create 4 images</label><br />
<label>Thumbnail / Big Image</label><br />
<!-- begin display uploaded image -->
<div id="upload_area" class="corners align_center">
please select image
</div><!-- begin display uploaded image -->
</form><!-- end form -->
What if:
upload.php
if location = slide1
//----------------------------------------- start edit here ---------------------------------------------//
$script_location = "http://demo.zmeutz.com/image_upload/"; // location of the script
$maxlimit = 1048576; // maxim image limit
$folder = "images"; // folder where to save images
// requirements
$minwidth = 200; // minim width
$minheight = 200; // minim height
$maxwidth = 2560; // maxim width
$maxheight = 1920; // maxim height
//thumbnails - 1 or 0 to allow or disallow
$thumb = 0; // allow to create thumb n.1
$thumb2 = 0; // allow to create thumb n.2
$thumb3 = 1; // allow to create thumb n.3
// allowed extensions
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.PNG', '.GIF', '.JPG', '.JPEG');
//----------------------------------------- end edit here ---------------------------------------------//
else if location = other then:
//----------------------------------------- start edit here ---------------------------------------------//
$script_location = "http://demo.zmeutz.com/image_upload/"; // location of the script
$maxlimit = 1048576; // maxim image limit
$folder = "images"; // folder where to save images
// requirements
$minwidth = 200; // minim width
$minheight = 200; // minim height
$maxwidth = 2560; // maxim width
$maxheight = 1920; // maxim height
//thumbnails - 1 or 0 to allow or disallow
$thumb = 0; // allow to create thumb n.1
$thumb2 = 0; // allow to create thumb n.2
$thumb3 = 1; // allow to create thumb n.3
// allowed extensions
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.PNG', '.GIF', '.JPG', '.JPEG');
//----------------------------------------- end edit here ---------------------------------------------//
Is it possible to transfer the location from one file to another file?
I updated the if into:
if ($_POST['location']=='slide1'){
will that able to capture the location?
Why write too many identical upload processors for the slide group, if simple functions can be written to handle all three?
well, the point is the distinguish the minimum and maximum height.
upload.php
<?php
if ($_POST['location']=='slide1'){
//----------------------------------------- start edit here ---------------------------------------------//
$script_location = "http://demo.zmeutz.com/image_upload/"; // location of the script
$maxlimit = 1048576; // maxim image limit
$folder = "images"; // folder where to save images
// requirements
$minwidth = 200; // minim width
$minheight = 200; // minim height
$maxwidth = 2560; // maxim width
$maxheight = 1920; // maxim height
//thumbnails - 1 or 0 to allow or disallow
$thumb = 0; // allow to create thumb n.1
$thumb2 = 0; // allow to create thumb n.2
$thumb3 = 1; // allow to create thumb n.3
// allowed extensions
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.PNG', '.GIF', '.JPG', '.JPEG');
//----------------------------------------- end edit here ---------------------------------------------//
}
else if ($_POST['location']=='other'){
//----------------------------------------- start edit here ---------------------------------------------//
$script_location = "http://demo.zmeutz.com/image_upload/"; // location of the script
$maxlimit = 1048576; // maxim image limit
$folder = "images"; // folder where to save images
// requirements
$minwidth = 200; // minim width
$minheight = 200; // minim height
$maxwidth = 2560; // maxim width
$maxheight = 1920; // maxim height
//thumbnails - 1 or 0 to allow or disallow
$thumb = 0; // allow to create thumb n.1
$thumb2 = 0; // allow to create thumb n.2
$thumb3 = 1; // allow to create thumb n.3
// allowed extensions
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.PNG', '.GIF', '.JPG', '.JPEG');
//----------------------------------------- end edit here ---------------------------------------------//
}
echo"<pre>";print_r($_GET);echo"</pre>";echo"<pre>";print_r($_POST);echo"</pre>";
// check that we have a file
if((!empty($_FILES["uploadfile"])) && ($_FILES['uploadfile']['error'] == 0)) {
// check extension
$extension = strrchr($_FILES['uploadfile']['name'], '.');
if (!in_array($extension, $extensions)) {
echo 'wrong file format, alowed only .png , .gif, .jpg, .jpeg
<script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
} else {
// get file size
$filesize = $_FILES['uploadfile']['size'];
// check filesize
if($filesize > $maxlimit){
echo "File size is too big.";
} else if($filesize < 1){
echo "File size is empty.";
} else {
// temporary file
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
// capture the original size of the uploaded image
list($width,$height) = getimagesize($uploadedfile);
// check if image size is lower
if($width < $minwidth || $height < $minheight){
echo 'Image is to small. Required minimum '.$minwidth.'x'.$minheight.'
<script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
} else if($width > $maxwidth || $height > $maxheight){
echo 'Image is to big. Required maximum '.$maxwidth.'x'.$maxheight.'
<script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
} else {
// all characters lowercase
$filename = strtolower($_FILES['uploadfile']['name']);
// replace all spaces with _
$filename = preg_replace('/\s/', '_', $filename);
// extract filename and extension
$pos = strrpos($filename, '.');
$basename = substr($filename, 0, $pos);
$ext = substr($filename, $pos+1);
// get random number
$rand = time();
// image name
$image = $basename .'-'. $rand . "." . $ext;
// check if file exists
$check = $folder . '/' . $image;
if (file_exists($check)) {
echo 'Image already exists';
} else {
// check if it's animate gif
$frames = exec("identify -format '%n' ". $uploadedfile ."");
if ($frames > 1) {
// yes it's animate image
// copy original image
copy($_FILES['uploadfile']['tmp_name'], $folder . '/' . $image);
// orignal image location
$write_image = $folder . '/' . $image;
//ennable form
echo '<img src="' . $write_image . '" alt="'. $image .'" alt="'. $image .'" width="500" /><br />
<input type="text" name="location" value="[IMG]'.$script_location.''.$write_image.'[/IMG]" class="location corners" />
<script language="javascript" type="text/javascript">window.top.window.formEnable();</script>';
} else {
// create an image from it so we can do the resize
switch($ext){
case "gif":
$src = imagecreatefromgif($uploadedfile);
break;
case "jpg":
$src = imagecreatefromjpeg($uploadedfile);
break;
case "jpeg":
$src = imagecreatefromjpeg($uploadedfile);
break;
case "png":
$src = imagecreatefrompng($uploadedfile);
break;
}
// copy original image
copy($_FILES['uploadfile']['tmp_name'], $folder . '/' . $image);
// orignal image location
$write_image = $folder . '/' . $image;
if ($thumb == 1){
// create first thumbnail image - resize original to 80 width x 80 height pixels
$newheight = ($height/$width)*80;
$newwidth = 80;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// write thumbnail to disk
$write_thumbimage = $folder .'/thumb-'. $image;
switch($ext){
case "gif":
imagegif($tmp,$write_thumbimage);
break;
case "jpg":
imagejpeg($tmp,$write_thumbimage,100);
break;
case "jpeg":
imagejpeg($tmp,$write_thumbimage,100);
break;
case "png":
imagepng($tmp,$write_thumbimage);
break;
}
}
if ($thumb2 == 1){
// create second thumbnail image - resize original to 125 width x 125 height pixels
$newheight = ($height/$width)*125;
$newwidth = 125;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// write thumbnail to disk
$write_thumb2image = $folder .'/thumb2-'. $image;
switch($ext){
case "gif":
imagegif($tmp,$write_thumb2image);
break;
case "jpg":
imagejpeg($tmp,$write_thumb2image,100);
break;
case "jpeg":
imagejpeg($tmp,$write_thumb2image,100);
break;
case "png":
imagepng($tmp,$write_thumb2image);
break;
}
}
if ($thumb3 == 1){
// create third thumbnail image - resize original to 125 width x 125 height pixels
$newheight = ($height/$width)*250;
$newwidth = 250;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagealphablending($tmp, false);
imagesavealpha($tmp,true);
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// write thumbnail to disk
$write_thumb3image = $folder .'/thumb3-'. $image;
switch($ext){
case "gif":
imagegif($tmp,$write_thumb3image);
break;
case "jpg":
imagejpeg($tmp,$write_thumb3image,100);
break;
case "jpeg":
imagejpeg($tmp,$write_thumb3image,100);
break;
case "png":
imagepng($tmp,$write_thumb3image);
break;
}
}
// all is done. clean temporary files
imagedestroy($src);
imagedestroy($tmp);
// image preview
if ($thumb == 1){
echo "<img src='" . $write_thumbimage . "' alt='". $image ."' /><br />
<input type='text' name='location' value='[IMG]".$script_location."". $write_thumbimage ."[/IMG]' class='location corners' /><br />
<br />";
}
if ($thumb2 == 1){
echo "<img src='" . $write_thumb2image . "' alt='". $image ."' /><br />
<input type='text' name='location' value='[IMG]".$script_location."". $write_thumb2image ."[/IMG]' class='location corners' /><br />
<br />";
}
if ($thumb3 == 1){
echo "<img src='" . $write_thumb3image . "' alt='". $image ."' /><br />
<input type='text' name='location' value='[IMG]".$script_location."". $write_thumb3image ."[/IMG]' class='location corners' /><br />
<br />";
}
echo "<img src='" . $write_image . "' alt='". $image ."' alt='". $image ."' width='500' /><br />
<input type='text' name='location' value='[IMG]".$script_location."".$write_image."[/IMG]' class='location corners' />
<script language='javascript' type='text/javascript'>window.top.window.formEnable();</script>
<div class='clear'></div>";
}
}
}
}
// database connection
include('inc/db.inc.php');
// insert into mysql database and show success message
mysql_query("INSERT INTO `image_upload` (`id`, `image`, `thumbnail`, `thumbnail2`, `thumbnail3`, `location` ) VALUES (NULL, '". $image ."', 'thumb-". $image ."', 'thumb2-". $image ."', 'thumb3-". $image ."','". $location ."')");
}
// error all fileds must be filled
} else {
echo '<div class="wrong">You must to fill all fields!</div>'; }
?>
line 269: mysql_query("INSERT INTO image_upload
(id
, image
, thumbnail
, thumbnail2
, thumbnail3
, location
) VALUES (NULL, '". $image ."', 'thumb-". $image ."', 'thumb2-". $image ."', 'thumb3-". $image ."','". $location ."')");
Notice: Undefined variable: location in C:\xampp\htdocs\free-prowebsite\site_pro\administrator\upload.php on line 269
You will need to define the variable $location.
How to define it? Is the code that I am writing in: input_image.php not enough to define location?
I thought the value from that code suppose to be past to the next file: input_image.php
this error
Notice: Undefined variable: location in C:\xampp\htdocs\free-prowebsite\site_pro\administrator\upload.php on line 269
is coming from this block..
// insert into mysql database and show success message
mysql_query("INSERT INTO `image_upload` (`id`, `image`, `thumbnail`, `thumbnail2`, `thumbnail3`, `location` ) VALUES (NULL, '". $image ."', 'thumb-". $image ."', 'thumb2-". $image ."', 'thumb3-". $image ."','". $location ."')");
}
so, you just have to define the $location.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.