So I wan't to use secureimage on CI coz' I don't want to use the default CAPTCHA helper since it doesn't have an audio option but I have a problem displaying the audio when using secureimage.
I copied the whole secureimage folder that I downloaded from the site to the library of CI.
Displaying the image is fine and also checking the inputted code. But my problem is displaying the audio file. I have no idea how to do it.
Here is how I displayed the image and for checking (already used the secureimage library):
function captcha_image(){
$img = new Securimage();
return $img->show();
}
public function captcha_check(){
$img = new Securimage();
$input = $this->input->post('imagecode');
$result = $img->check($input);
if($result)
$message = "success";
else
$message = "try again";
}
My view:
<img src="<?php echo site_url('form/captcha_image') ?>" alt='captcha' />
If you are using this library
https://github.com/subdesign/CI-HTI-Securimage
So The Method to get the Audio file is
$img->outputAudioFile();
But you have to configure ( settings ) the audio path directory and make sure its rewritable
$settings['audio_path'] = '....';// If you didn't configure this it will secureimage library path and follow by dir /audio/
$settings['audio_noise_path'] = '...';//save as above audio path
$settings['audio_use_noise'] = true; // true or false;
$settings['degrade_audio'] = true; // true or false;
// Then init the secureimage with the options
$img = new Securimage($settings);
$img->show(); // this will show the image src
$img->outputAudioFile(); // this will output the audio file to the browser
Related
I'm currently creatting a mailer and embed image. So when I set a specific directory ( ./upload/tmp_logo_company_upload/company_logo_resized.jpg ) for image it successfully send to my email and it shows the image that i embed.
But I want is to get all the image in the upload directory so whenever I run the script all images from upload folder will send to me. Can someone help me out for this, Below you will see my code. Thanks.
if( !defined('sugarEntry') ) define( 'sugarEntry',true );
// Set required classes
require_once('include/entryPoint.php');
// Get access to globals
global $db, $current_user, $timedate;
$arRecipientsId = array();
$objDefaultMail = new Email();
$objDefault = $objDefaultMail->getSystemDefaultEmail();
$objMail = new SugarPHPMailer();
$objMail->setMailerForSystem();
$objMail->From = $objDefault['email'];
$objMail->FromName = $objDefault['name'];
$objMail->Subject = "";
// Set the Location of photo
$strLocation = './upload/tmp_logo_company_upload/company_logo_resized.jpg';
// Add image
$objMail->AddEmbeddedImage($strLocation, 'company_logo_resized.jpg');
//
$objMail->Body = "Here. <img src='cid:company_logo_resized.jpg'>";
// Send as HTML
$objMail->IsHTML(true);
// Clear previous email data
$objMail->ClearAllRecipients();
$objMail->ClearReplyTos();
$objMail->prepForOutbound();
// Store recipients
$arRecipientsId[] = "1"; //crmonline
// Add as BCC
$objMail->AddBCC('email#gmail.com');
// Mail sent?
if( $objMail->send() ) {
// echo "Email Has Been Sent";
$GLOBALS['log']->fatal("WORKING");
}
// }
There's no need to call ClearAllRecipients or ClearReplyTos - the things those clear are already empty because you have a new instance.
To iterate over all the files in a folder, use a DirectoryIterator - that will get all the filenames you need, so you just need to call addEmbeddedImage for each and add <img src="cid:xxx"> tags for each image you want to embed.
$dir = './upload/tmp_logo_company_upload';
$cidn = 0;
foreach (new DirectoryIterator($dir) as $fileInfo) {
if($fileInfo->isDot() or $fileInfo->isDir()) continue;
$objMail->addEmbeddedImage($dir . DIRECTORY_SEPARATOR . $fileInfo->getFilename(), "img_$cidn");
$mailObj->Body .= "<img src=\"cid:img_$cidn\">";
++$cidn;
}
That said, this is an inefficient way of using images in email - it is much better to use HTTP links to the images - that way they are only loaded when the recipients ask for them, rather than sending them regardless.
Its pretty simple , you are missing complete image public path
change this to following
$objMail->Body = "Here. <img src='cid:company_logo_resized.jpg'>";
To (Image Public Path including http)
$objMail->Body = "Here. <img src='http://example.com/publicppath /company_logo_resized.jpg'>";
Adding code for Reading the Image from dir
//path to the dir
$dir = '/upload';
$files = scandir($dir);
foreach ($files as $image) {
$all_img .= " <img src='http://example.com/imagepath/".$image."'><br>";
}
//for embeding image
foreach ($files as $image) {
$im = file_get_contents($image);
$em_img .="<img src='data:image/jpg;base64,".base64_encode($im)."'> <br>"
}
//via public path
$objMail->Body = "Here ".$all_img;
//or embed sending
$objMail->Body = "Here ".$em_img;
it should work
So I am using this script to upload a file to a directory and show it live.
<?php
function UploadImage($settings = false)
{
// Input allows you to change where your file is coming from so you can port this code easily
$inputname = (isset($settings['input']) && !empty($settings['input']))? $settings['input'] : "fileToUpload";
// Sets your document root for easy uploading reference
$root_dir = (isset($settings['root']) && !empty($settings['root']))? $settings['root'] : $_SERVER['DOCUMENT_ROOT'];
// Allows you to set a folder where your file will be dropped, good for porting elsewhere
$target_dir = (isset($settings['dir']) && !empty($settings['dir']))? $settings['dir'] : "/uploads/";
// Check the file is not empty (if you want to change the name of the file are uploading)
if(isset($settings['filename']) && !empty($settings['filename']))
$filename = $settings['filename'] . "sss";
// Use the default upload name
else
$filename = preg_replace('/[^a-zA-Z0-9\.\_\-]/',"",$_FILES[$inputname]["name"]);
// If empty name, just return false and end the process
if(empty($filename))
return false;
// Check if the upload spot is a real folder
if(!is_dir($root_dir.$target_dir))
// If not, create the folder recursively
mkdir($root_dir.$target_dir,0755,true);
// Create a root-based upload path
$target_file = $root_dir.$target_dir.$filename;
// If the file is uploaded successfully...
if(move_uploaded_file($_FILES[$inputname]["tmp_name"],$target_file)) {
// Save out all the stats of the upload
$stats['filename'] = $filename;
$stats['fullpath'] = $target_file;
$stats['localpath'] = $target_dir.$filename;
$stats['filesize'] = filesize($target_file);
// Return the stats
return $stats;
}
// Return false
return false;
}
?>
<?php
// Make sure the above function is included...
// Check file is uploaded
if(isset($_FILES["fileToUpload"]["name"]) && !empty($_FILES["fileToUpload"]["name"])) {
// Process and return results
$file = UploadImage();
// If success, show image
if($file != false) { ?>
<img src="<?php echo $file['localpath']; ?>" />
<?php
}
}
?>
The thing I am worried about is that if a person uploads a file with the same name as another person, it will overwrite it. How would I go along scraping the filename from the url and just adding a random string in place of the file name.
Explanation: When someone uploads a picture, it currently shows up as
www.example.com/%filename%.png.
I would like it to show up as
www.example.com/randomstring.png
to make it almost impossible for images to overwrite each other.
Thank you for the help,
A php noob
As contributed in the comments, I added a timestamp to the end of the filename like so:
if(isset($settings['filename']) && !empty($settings['filename']))
$filename = $settings['filename'] . "sss";
// Use the default upload name
else
$filename = preg_replace('/[^a-zA-Z0-9\.\_\-]/',"",$_FILES[$inputname]["name"]) . date('YmdHis');
Thank you for the help
okay i someone find out how to upload blobs in container of using php on azure, but when even i view the image with plain url like https://my.blob.url.net/my_image_folder/my_image_name.jpg the browser prompts to download the image, instead of viewing the image, like normal image is viewed on browser, here is the code i'm using while uploading
<?php
require_once __DIR__.'/vendor/autoload.php';
use WindowsAzure\Common\ServicesBuilder;
$connectionString = 'DefaultEndpointsProtocol=http;AccountName=account_name;AccountKey=my_key_value';
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$content = fopen('folder/image.jpg','r');
$blob_name = 'image_name.jpg';
try
{
$blobRestProxy->createBlockBlob("container_name", $blob_name, $content);
}
catch(ServiceException $e)
{
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
this code is working fine, but when accessing the url, it prompts download option, which means i cannot use for img html tag
You have to set the blob's content type to an appropriate mime type. The following is a snippet in C# that shows how this can be done:
entryData.DestinationBlob.Properties.ContentType = "image/jpeg";
entryData.DestinationBlob.SetProperties();
We need to set its property Content type through Blob Options class.
PHP :
namespace - use MicrosoftAzure\Storage\Blob\Models\CreateBlobOptions;
//use code where you are creating blob
$opts = new CreateBlobOptions();
//$opts->setCacheControl('test');
$opts->setContentEncoding('UTF-8');
$opts->setContentLanguage('en-us');
//$opts->setContentLength(512);
$opts->setContentMD5(null);
$opts->setContentType($mimeType);
$blobRestProxy->createBlockBlob($containerName, $indexFile, $content,$opts);
$mimeType is Type of your file text/html, text/pdf. It will work in git.
package : "microsoft/windowsazure": "^0.5"
I want to save a screenshot from my Flex app on the Webserver (LAMP).
Here is the Flex code:
private function getBitmapData( target : UIComponent ) : BitmapData
{
var bd : BitmapData = new BitmapData( target.width, target.height );
var m : Matrix = new Matrix();
bd.draw( target, m );
return bd;
}
Now, how do I send / receive this data to the server?
You are going to have to use a HttpService to post the data to a page on your website. When I implemented this I posted the Image data as a Base64 encoded string to a PHP page that used the GD library to save it to a png file on the server. Here is a simplified example of what my code looked like
Flex Code
public function saveImg():void{
var bd:BitmapData = new BitmapData(mycanvas.width,mycanvas.height);
bd.draw(mycanvas);
var ba:ByteArray = PNGEncoder.encode(bd);
var encoded:String = Base64.encodeByteArray(ba);
var objSend:Object = new Object;
objSend.data = encoded;
objSend.filename = _imgResult;
writeImage.send(objSend);
}
<mx:HTTPService id="writeImage" url="/saveImage.php" method="POST" resultFormat="text" result="resultHandler(event)"/>
PHP File (saveImage.php)
<?php
//check for the posted data and decode it
if (isset($_POST["data"]) && ($_POST["data"] !="")){
$data = $_POST["data"];
$data = base64_decode($data);
$im = imagecreatefromstring($data);
}
//make a file name
$filename = "test"
//save the image to the disk
if (isset($im) && $im != false) {
$imgFile = "/etc/www/html/".$filename.".png";
//delete the file if it already exists
if(file_exists($imgFile)){
unlink($imgFile);
}
$result = imagepng($im, $imgFile);
imagedestroy($im);
echo "/".$filename.".png";
}
else {
echo 'Error';
}
?>
On the flex side I am using the Base64Encode utilty from dynamicflash, but now that there is one built into flex you could use that instead. In your php config you will need to make sure you have the GD library enabled so that you can save the image.
Of course this is a very simple example and does not take into account all the error handling and security concerns needed, but should provide you a good base to get going with.
Having a problem with image manipulation in codeigniter - it bombs when I get to $this->image_lib->resize(). I just can't see the error.
Code:
$imagemanip = array();
$imagemanip['image_library'] = 'gd2';
$imagemanip['source_image'] = '/resources/images/butera-fuma-dolce.jpg';
$imagemanip['new_image'] = '/resources/images/thumb_butera-fuma-dolce.jpg';
$imagemanip['create_thumb'] = TRUE;
$imagemanip['maintain_ratio'] = TRUE;
$imagemanip['width'] = 350;
$imagemanip['height'] = 350;
$this->load->library('image_lib', $imagemanip);
if ( ! $this->image_lib->resize()) {
echo $this->image_lib->display_errors();
}
As I said, it bombs at $this->image_lib->resize(), showing no further output, and does not generate an error.
gd2 is installed (per phpinfo()). I can view the original image with plain html tags. What am I doing wrong?
The path should be relative to the root of your website, where your index.php is located, ie:
don't do this:
$imagemanip['source_image'] = '/resources/images/butera-fuma-dolce.jpg';
do that:
$imagemanip['source_image'] = 'resources/images/butera-fuma-dolce.jpg';
Alternatively, you can use CodeIgniter's absolute path constant, like so:
$imagemanip['source_image'] = FCPATH.'resources/images/butera-fuma-dolce.jpg';
You do not need to specify the 'new_image' config option when using the 'create_thumb' option.
The library will write the file to a file of the same name with a _thumb appended.
Also make sure the correct permissions are set for writing.