Created
November 30, 2012 15:06
-
-
Save 6LYTH3/4176285 to your computer and use it in GitHub Desktop.
upload image file in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$page = $_SERVER['PHP_SELF']; | |
$column = 5; | |
$base = "data"; | |
$thumbs = "thumbs"; | |
$get_album = $_GET['album']; | |
if (!$get_album) { | |
echo "<b>Select an album: </b><p />"; | |
$handle = opendir($base); | |
while (($file = readdir($handle)) !== FALSE) { | |
if (is_dir($base."/".$file) && $file != "." && $file != "..") { | |
echo "<a href='$page?album=$file'>$file</a>"."<br>"; | |
} | |
} | |
} | |
else{ | |
if (!is_dir($base."/".$get_album)) { | |
echo "album doesnt exist."; | |
}else{ | |
echo "<b>$get_album</b><p />"; | |
$handle = opendir($base."/".$get_album); | |
while (($file = readdir($handle)) !== FALSE) { | |
if ($file != "." && $file != "..") { | |
echo "<img src='$base/$get_album/$file'><br>"; | |
} | |
} | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$image1 = 'data/album2/1.jpeg'; | |
$image2 = 'data/album1/2.jpeg'; | |
$image3 = 'data/album1/3.jpeg'; | |
$bg = 'images/11.jpg'; | |
$image1cre = imagecreatefromjpeg($image1); | |
$image2cre = imagecreatefromjpeg($image2); | |
$image3cre = imagecreatefromjpeg($image3); | |
$ims = imagecreatefromjpeg($bg); | |
$x = imagesx($image1cre); | |
$y = imagesy($image1cre); | |
$im = imagecreatetruecolor($y-300, $x); | |
$im1 = imagecreatetruecolor($y, $x); | |
$im2 = imagecreatetruecolor($y-200, $x); | |
// Set the border and fill colors | |
//$border = imagecolorallocate($im, 0, 0, 0); | |
//$fill = imagecolorallocate($im, 255, 0, 0); | |
$black = imagecolorallocate($im, 0, 0, 0); | |
$white = imagecolorallocate($im, 255, 255, 255); | |
$image1cre = imagerotate($image1cre, 90, 0); | |
//list($width, $height) = getimagesize($image1); | |
//$newWidth = $width * 0.5; | |
//$newHeight = $height * 0.5; | |
//$thumb = imagecreatetruecolor($newWidth, $newHeight); | |
//imagecopyresized($thumb, $image1cre, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); | |
// Fill the selection | |
//imagefilltoborder($thumb, 100, 100, $border, $fill); | |
//$width_image = imagesx($image1cre); | |
//$height_image = imagesy($image1cre); | |
//imagefill($im,0,0,$black); | |
imagecopy( $im1, $image1cre, 0, 0, 0, 0, $y-100, $x); | |
$im1 = imagerotate($im1, 180, 0); | |
imagecopy( $im2, $im1, 0, 0, 0, 0, $y-100, $x); | |
//imagecopy( $im, $im1, 0, 0, 300, 300, 100, 300, 100); | |
//imagecopymerge( $ims, $thumb, 10, $newHeight+500, 0, 0, $newWidth, $newHeight,100); | |
//imagecopy($ims, $thumb, 10, 10, 20, 13, 300, 300); | |
$im2 = imagerotate($im2, 180, 0); | |
imagecopy( $im, $im2, 0, 0, 0, 0, $y-100, $x); | |
$im = imagerotate($im, 270, 0); | |
header('Content-Type: image/jpeg'); | |
imagejpeg($im); | |
//imagejpeg($im, "images/image2.jpeg", 100); | |
//imagejpeg($thumb); | |
//imagedestroy($thumb); | |
imagedestroy($im); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$image1 = 'data/album1/1.jpeg'; | |
$image2 = 'data/album1/2.jpeg'; | |
$image3 = 'data/album1/3.jpeg'; | |
$image1cre = imagecreatefromjpeg($image1); | |
$image2cre = imagecreatefromjpeg($image2); | |
$image3cre = imagecreatefromjpeg($image3); | |
$im = imagecreate(1000, 1000); | |
$black = imagecolorallocate($im, 0, 0, 0); | |
$white = imagecolorallocate($im, 255, 255, 255); | |
$width_image = imagesx($image1cre); | |
$height_image = imagesy($image1cre); | |
imagefill($im,0,0,$black); | |
imagecopymerge( $im, $image1cre, 10, 10, 0, 0, $width_image, $height_image/2, 100); | |
imagecopymerge( $im, $image2cre, 10, ($height_image/2)+50, 0, 0, $width_image, $height_image/2, 100); | |
imagecopymerge( $im, $image3cre, 10, ($height_image/2)+($height_image/2)+100, 0, 0,$width_image, $height_image,100); | |
header('Content-Type: image/png'); | |
imagejpeg($im); | |
imagedestroy($im); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_FILES['upload']) === true) { | |
$file = $_FILES['upload']; | |
for ($i = 0; $i < count($file['name']) ; $i++) { | |
$file_name = $file['name'][$i]; | |
$file_tmp = $file['tmp_name'][$i]; | |
move_uploaded_file($file_tmp, 'images/'.$file_name); | |
} | |
} | |
?> | |
<form action="" method="POST" enctype="multipart/form-data"> | |
<p> | |
<input type="file" name="upload[]" multiple /> | |
<input type="submit" value="Upload"/> | |
</p> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_FILES['image'])) { | |
$errors = array(); | |
$allowed_ext = array('jpg','jpeg','png','gif'); | |
$file_name = $_FILES['image']['name']; | |
$file_ext = strtolower(end(explode(".", $file_name))); | |
$file_size = $_FILES['image']['size']; | |
$file_tmp = $_FILES['image']['tmp_name']; | |
if (in_array($file_ext, $allowed_ext) === false ) { | |
$errors[] = 'Extenstion not allowed'; | |
} | |
if ($file_size > 2097152) { | |
$errors[] = 'File size must be under 2mb'; | |
} | |
if (empty($errors)) { | |
if(move_uploaded_file($file_tmp, 'images/'.$file_name)){ | |
echo "File Uploaded"; | |
} | |
}else{ | |
foreach ($errors as $error) { | |
echo $error , '<br>'; | |
} | |
} | |
} | |
?> | |
<form action="" method="POST" enctype="multipart/form-data"> | |
<p> | |
<input type="file" name="image" /> | |
<input type="submit" value="Upload"/> | |
</p> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment