I have search many time but i did not find any solution so in this case i can not post any code. sorry for this.
I have faced a problem that how can i check that 2 or more video same like i have media folder and many video upload in this folder then when i upload new video then need to check that video already exit or not.
1. if i have video demo.mp4 then when i will try to upload same video then give error
2. if i change video name like demo.mp4 to demo1.mp4 then i will give same error cause video name different but video content same
3. if i upload video demo5.mp4 then show me no error
i already checked image compare using
include('compareImages.php');
$new_image_name = $uploadfile_temp;
$compareMachine = new compareImages($new_image_name);
$image1Hash = $compareMachine->getHasString();
$files = glob("uploads/*.*");
$check_image_duplicate = 0;
for ($i = 0; $i < count($files); $i++) {
$filename = $files[$i];
$image2Hash = $compareMachine->hasStringImage($filename);
$diff = $compareMachine->compareHash($image2Hash);
if($diff < 10){
$check_image_duplicate = 1;
//unlink($new_image_name);
break;
}
}
but i can not compare video. someone help me
Tested and works fine, code taken from :http://php.net/manual/en/function.md5-file.php#94494 not mine.
<?php
define('READ_LEN', 4096);
if(files_identical('demo.mp4', 'demo1.mp4'))
echo 'files identical';
else
echo 'files not identical';
// pass two file names
// returns TRUE if files are the same, FALSE otherwise
function files_identical($fn1, $fn2) {
if(filetype($fn1) !== filetype($fn2))
return FALSE;
if(filesize($fn1) !== filesize($fn2))
return FALSE;
if(!$fp1 = fopen($fn1, 'rb'))
return FALSE;
if(!$fp2 = fopen($fn2, 'rb')) {
fclose($fp1);
return FALSE;
}
$same = TRUE;
while (!feof($fp1) and !feof($fp2))
if(fread($fp1, READ_LEN) !== fread($fp2, READ_LEN)) {
$same = FALSE;
break;
}
if(feof($fp1) !== feof($fp2))
$same = FALSE;
fclose($fp1);
fclose($fp2);
return $same;
}
?>
Related
I decided to try out the latest PHP ZIP functions for extracting data and something odd has happened. This PHP script is to read data from packed files of a specific extension (gob or goo) and display them in an XML format for further use later.
$zip = new ZipArchive;
$zipres = $zip->open($zipfilename);
if($zipres === true)
{
for($i = 0; $i < $zip->numFiles; $i++)
{
echo "\t<entry id=\"".$i."\">".$zip->getNameIndex($i)."</entry>\n";
if(strripos($zip->getNameIndex($i),".gob") !== false || strripos($zip->getNameIndex($i),".goo") !== false)
{
$zipentry = $zip->getStreamIndex($i);
return;
if($zipentry)
{
$packagenames[] = $zip->getNameIndex($i);
$wholeGOB[] = stream_get_contents($zipentry);
fclose($zipentry);
}
else
echo "\t<error>Error reading entry ".$zip->getNameIndex($i)."</error>";
}
}
$zip->close();
}
else
echo "\t<error>Invalid ZIP file</error>\n\t<code>".$zipres."</code>\n";
Having the return; before getStreamIndex will print out the <entry>s, but as soon as I move the return; to after getStreamIndex I get a blank page (even in view-source). Am I doing something wrong, or has this function always been a bit off? And what alternative would you recommend?
I tried to code a script, that put some data in a zip file. I think I have done all right, but he does not create the zip file.
I already tried a lot, but don´t find the issue.
<?php
$sql_abfrage_cloud = "SELECT * FROM dateien WHERE code = '$zugang' ORDER BY id";
$abfrage_cloud = $mysqli->query($sql_abfrage_cloud);
$verzeichnis = '/upload/';
$zip_name = date("dHis").'_fc.zip';
$anz_dateien = 0;
$error = 'fatal';
while($fetch = $abfrage_cloud->fetch_assoc()){
$anz_dateien = $anz_dateien + 1;
$zip_datei[$anz_dateien] = $fetch['path'];
}
$zip_arch = new ZipArchive;
$status = $zip_arch->open($zip_name, ZipArchive::CREATE);
if($status==true){
foreach($zip_datei as $datei){
$zip_arch->addFile($verzeichnis.$datei, $datei);
}
if(file_exists($zip_name)){
$error = 'false';
} else {
$error = 'true';
}
}
?>
I expected that $error would be 'false' but it´s 'true'.
You need to call $zip_arch->close() to save finish writing the file.
You should also use === when comparing the result of $zip_archive->open(), since the non-true results are numbers, and any non-zero number compares equal to true when type juggling is allowed.
$zip_arch = new ZipArchive;
$status = $zip_arch->open($zip_name, ZipArchive::CREATE);
if($status===true){
foreach($zip_datei as $datei){
$zip_arch->addFile($verzeichnis.$datei, $datei);
}
$zip_arch->close();
if(file_exists($zip_name)){
$error = 'false';
} else {
$error = 'true';
}
}
I am trying to display an error if a file does not upload. The crux of my problem is that my $status() array doesn't return the values I append in an if statement within a foreach loop.
Can someone enlighten me as to what is going on and what I am doing wrong? I'd like the status values in the foreach loop to append and return outside the loop.
Code below.
$status = array();
// Check that file within size restrictions, then upload.
foreach($request->getFiles() as $file)
{
$file_dir = sfConfig::get("sf_data_dir") . '/retail/order/' . $order_id . '/';
if (!is_dir($file_dir))
{
mkdir($file_dir, 0777, true);
}
$maxsize = 332027;
if(($file['size'] >= $maxsize) || ($file['size'] == 0))
{
$status[] = 0;
}
else
{
move_uploaded_file($file['tmp_name'], $file_dir . $file['name']);
$attachment = new Attachment();
$attachment->setName($file['name']);
$attachment->setPath($file_dir);
$attachment->setSize($file['size']);
$attachment->setCreatedTs('now');
$attachment->save();
$app_attachment = new ApendedAttachment();
$app_attachment->setAttachmentId($attachment->getAttachmentId());
$app_attachment->setWebOrderId($order_id);
$app_attachment->setCreatedTs('now');
$app_attachment->save();
$status[] = 1;
}
}
if (in_array(1, $status))
{
$this->getUser()->setFlash('success', 'Thank you. Your cart has been saved.');
}
else
{
$this->getUser()->setFlash('error', 'Please upload files less than 20MB.');
}
$this->redirect('order/detail?id=' . $order->getWebOrderId());
You are not assigning values to the status array correctly. You probably want to increment an index as you go through the array of files:
$i = 0;
for each(){
...
$status[$i] = 1;
...
$i++;
}
Sorry for the bad code format. Doing this on my mobile device.
i've problem with my code here.
The case is, i have multiple input file form, i need to get name of current array (which contain database id) and upload the file from it.
Here's in my views
foreach($result2 as $result3)
{
print "
<tr>
<td><input type=file name=baddismantling[".$result3['iddeployment']."] size=20></td>
</tr>
";
}
so, there'll be various of upload form and name too, but it always unique.
and after user click submit button, that form will call function in my controller, and here's
the function that handled it
private function _ready_to_start($sessiondata)
{
if($post['doSubmitDismantlingAction'] == 'uploadbad')
{
while ($fruit_name = current($_FILES['baddismantling']['name']))
{
if($fruit_name != false)
{
//GET ID FROM DEPLOYMENT DB
$deploymentid = key($_FILES['baddismantling']['name']);
$file = "baddismantling[$deploymentid]";
if(!$this->upload->do_upload($file))
{
$check3[] = $this->upload->display_errors()." target: ".$file;
}
$check2 = $this->upload->data();
}
next($_FILES['baddismantling']['name']);
}
//SHOW RESULT WHILE UPLOADING
print implode($check3);
}
}
as you see,i've successful with getting the
$deploymentid = 1
as i wish...but, browser give me :
You did not select a file to upload. target: baddismantling[1]
anyone can give me suggestion about that problem?or there's something wrong with my code?
as note :
there's no problem with configuration $this->upload-> because i've
successfull with a single upload form only
thanks for your time with my question, and i've "luckily" got my own solving from question above with this code :
$check3 = array();
$count = 0;
$check = ($_FILES == true ? count($_FILES['baddismantling']['name']) : (0));
while ($fruit_name = ($check == true && $check > 0 ? current($_FILES['baddismantling']['name']) : (false)) || $count <= $check){
$count++;
if($fruit_name == true && key($_FILES['baddismantling']['name']) == true)
{
$iddeployment = key($_FILES['baddismantling']['name']);
/*THIS PART WAS HELPING ME*/if($_FILES['baddismantling']['name'][$iddeployment] == true)
{
$_FILES['userfile']['name'] = $_FILES['baddismantling']['name'][$iddeployment];
$_FILES['userfile']['type'] = $_FILES['baddismantling']['type'][$iddeployment];
$_FILES['userfile']['tmp_name'] = $_FILES['baddismantling']['tmp_name'][$iddeployment];
$_FILES['userfile']['error'] = $_FILES['baddismantling']['error'][$iddeployment];
$_FILES['userfile']['size'] = $_FILES['baddismantling']['size'][$iddeployment];
if (!$this->upload->do_upload())
{
$check3[] = $this->upload->display_errors();
}
else
{
$uploaddata = $this->upload->data();
$result['badfilename'] = $uploaddata['full_path'];
$result['id'] = $iddeployment;
$sql = $this->sql->updatedismantlingBAD($result);
}
}
}
next($_FILES['baddismantling']['name']);}
My function searches google for the specific keyword and then checks for the site and then returns the what position it is on google (its for my seo dashboard) but it always return's 0, hopefully some fresh eyes can find the faults
<?php
function GoogleSerp($searchquery, $searchurl){
if(!empty($searchquery) && !empty($searchurl))
{
$query = str_replace(" ","+",$searchquery);
$query = str_replace("%26","&",$query);
// How many results to search through.
$total_to_search = 50;
// The number of hits per page.
$hits_per_page = 10;
// Obviously, the total pages / queries we will be doing is
// $total_to_search / $hits_per_page
// This will be our rank
$position = 0;
// This is the rank minus the duplicates
$real_position = 0;
$found = NULL;
$lastURL = NULL;
for($i=0;$i<$total_to_search && empty($found);$i+=$hits_per_page)
{
// Open the search page.
// We are filling in certain variables -
// $query,$hits_per_page and $start.
// $filename = "http://www.google.co.uk/xhtml?q=$query&start=$i&sa=N";
$filename = "http://www.google.co.uk/m?q=$query&num=$hits_per_page&filter=0&start=$i&sa=N";
$file = fopen($filename, "r");
if (!$file)
{
return "error";
}
else
{
// Now load the file into a variable line at a time
while (!feof($file))
{
$var = fgets($file, 1024);
// Try and find the font tag google uses to show the site URL
if(eregi("<span class=\"c\">(.*)</span>",$var,$out))
{
// If we find it take out any <B> </B> tags - google does
// highlight search terms within URLS
$out[1] = strtolower(strip_tags($out[1]));
// Get the domain name by looking for the first /
$x = strpos($out[1],"/");
// and get the URL
$url = substr($out[1],0,$x);
$url = str_replace("/","",$url);
$position++;
// If you want to see the hits, set $trace to something
// if($trace)return($url."<br>");
// If the last result process is the same as this one, it
// is a nest or internal domain result, so don't count it
// on $real_position
if(strcmp($lastURL,$url)<>0)$real_position++;
$lastURL = $url;
// Else if the sites match we have found it!!!
if(strcmp($searchurl,$url)==0)
{
$found = $position;
// We quit out, we don't need to go any further.
break;
}
}
}
}
fclose($file);
}
if($found)
{
$result = $real_position;
}else{
$result = 0;
}
}
return $result;
}
?>
Try urlencode() instead of the two replaces on the query.