Zend_Validate_File_IsImage can't detect PNG - zend-framework

I'm using Zend_Validate_File_IsImage on a file upload, just using this code, essentially:
$adapter = new Zend_File_Transfer_Adapter_Http;
$adapter->addValidator('IsImage', false);
if (!$adapter->receive()) { /* error... */ }
I took the image found here (just happened to have that page open):
http://www.codinghorror.com/blog/images/coding-horror-official-logo-small.png
saved it as horror.png and tried to uploaded it, and it works fine on my dev machine (Mac OSX), but it fails on the production server (Ubuntu) saying:
File 'horror.png' is no image, 'text/plain' detected

Related

How to show PDF from .net maui app on Windows

I am just trying to show a PDF file from my .NET MAUI application on Windows and it is giving me the error below.
"System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'C:\Users<username>\Documents\helpfile.pdf' with working directory 'C:\WINDOWS\system32'. The specified executable is not a valid application for this OS platform.'"
My code is below. It has worked in a WPF app but won't work here.
Process.Start("C:\\Users\\<username>\\Documents\\helpfile.pdf"); // removed the username here and above in error message
also tried: (getting helpfile.pdf from install directory)
string _asmPath = Assembly.GetExecutingAssembly().Location;
int lastIndex = _asmPath.LastIndexOf('\\');
string helpfilePath = $"{_asmPath.Substring(0, lastIndex)}\\helpfile.pdf";
ProcessStartInfo startInfo = new ProcessStartInfo(helpfilePath);
Process.Start(startInfo);
and I get a similar error:
"System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'C:\Projects\SnapSignalTel\bin\Debug\net6.0-windows10.0.19041.0\win10-x64\AppX\helpfile.pdf' with working directory 'C:\WINDOWS\system32'. The specified executable is not a valid application for this OS platform.'"
How can I open this PDF document (helpfile.pdf) in a MAUI app on Win10?
Thanks for any help!
use Launcher
await Launcher.Default.OpenAsync(new OpenFileRequest("Some Title", new ReadOnlyFile(filepath)));

unity web request got error for local files on mobile

I load images from my local destination to unity the code is:
Texture2D imgTexture;
using (UnityWebRequest req = UnityWebRequestTexture.GetTexture(filePath))
{
yield return req.SendWebRequest();
if (req.isNetworkError)
{
Debug.Log(req.error);
}
else
{
imgTexture = DownloadHandlerTexture.GetContent(req);
}
}
it works on pc but when I run on android emulator I get an error
Cannot connect to destination host
the local file directory comes from simple file browsing plugin so I am thinking directory cannot be wrong.
is it a permission problem how can I fix this?

invalid argument: File not found error when trying to upload a file

I have an E2E test to upload a file to the application which works on my local machine but fails to run on Browserstack. But fails with reason :
invalid argument: File not found : /home/travis/build/xx/xx/e2e/src/xx/testfile
Here is the code
let fileToUpload = 'testfile';
let absolutePath = path.resolve(__dirname, fileToUpload);
await browser.setFileDetector(new remote.FileDetector());
let fileElem = $('input[type="file"]');
await fileElem.sendKeys(absolutePath);
I have the files upload in my code base for travis to pick them.
Any inputs are appreciated.
Thanks
Since the file upload is working from your local machine, you can try using the Local File Detector Option.
driver.setFileDetector(new LocalFileDetector());
driver.get("http://www.fileconvoy.com/");
driver.findElement(By.id("upfile_0")).sendKeys("C:\\Users\\hello\\url.txt");
driver.findElement(By.id("readTermsOfUse")).click();
driver.findElement(By.name("form_upload")).submit();
The above code snippet will upload a file located on the local machine. The same details are available here: https://www.browserstack.com/automate/java#enhancements-uploads-downloads
You can port this in the language of your choice.
((RemoteWebDriver) driver).setFileDetector(new LocalFileDetector());
driver.get("https://www.monsterindia.com/seeker/registration");
WebElement browser = driver.findElement(By.xpath("//*[#id=\"file-upload\"]"));
//Upload button xpath
browser.sendKeys("add here upload file path");
System.out.println("File upload Successfully");
This will also simple way to upload file. I have worked this code in Chrome browser.
This code worked for me to run the test in BrowserStack. I'm using Java-selenium-Jenkins-BrowserStack
WebElement uploadFile = driver.findElement(By.xpath("//input[#type='file']"));
((RemoteWebElement)uploadFile).setFileDetector(new LocalFileDetector());
upload_file.sendKeys(System.getProperty("user.dir")+"/src/main/java/resources/common/<Name of your file>.csv");

php fopen with ssh2.sftp is failing with special characters

The below is working just fine
$stream = fopen($connection_string . "/var/tmp/test.test", 'r');
But
$stream = fopen($connection_string . "/var/tmp/test.#test", 'r');
Fails with an error message:
Warning: fopen(): Unable to open ssh2.sftp://Resource id #108/var/tmp/test.#test on remote host in...
test.test and test#test are working fine, only the combination of test.#test is failing.
ssh2_scp_recv() handles test.#test just fine.
CentOS release 5.8 (Final)
PHP 5.2.17
Is this a php bug? Or some special character escaping is required?
it would be interesting to know how well it works with phpseclib. eg.
<?php
include('Net/SFTP.php');
$sftp = new Net_SFTP('www.domain.tld');
if (!$sftp->login('username', 'password')) {
exit('Login Failed');
}
// outputs the contents of filename.remote to the screen
echo $sftp->get('filename.remote');
// copies filename.remote to filename.local from the SFTP server
$sftp->get('filename.remote', 'filename.local');
?>
src: http://phpseclib.sourceforge.net/sftp/examples.html#get
if phpseclib didn't work you could enable logging, with phpseclib, and see what the phpseclib logs say. eg. do define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX); after you include Net/SFTP.php and then do $sftp->getLog() after you try to download the file.

ASP.NET MVC: Can an MSI file be returned via a FileContentResult without breaking the install package?

I'm using this code to return a FileContentResult with an MSI file for the user to download in my ASP.NET MVC controller:
using (StreamReader reader = new StreamReader(#"c:\WixTest.msi"))
{
Byte[] bytes = Encoding.ASCII.GetBytes(reader.ReadToEnd());
return File(bytes, "text/plain", "download.msi");
}
I can download the file, but when I try to run the installer I get an error message saying:
This installation package could not be
opened. Contact the application vendor
to verify that this is a valid Windows
Installer package.
I know the problem isn't C:\WixTest.msi, because it runs just fine if I use the local copy. I don't think I'm using the wrong MIME type, because I can get something similar with just using File.Copy and returning the copied file via a FilePathResult (without using a StreamReader) that does run properly after download.
I need to use the FileContentResult, however, so that I can delete the copy of the file that I'm making (which I can do once I've loaded it into memory).
I'm thinking I'm invalidating the install package by copying or encoding the file. Is there a way to read an MSI file into memory, and to return it via a FileContentResult without corrupting the install package?
Solution:
using (FileStream stream = new FileStream(#"c:\WixTest.msi", FileMode.Open))
{
BinaryReader reader = new BinaryReader(stream);
Byte[] bytes = reader.ReadBytes(Convert.ToInt32(stream.Length));
return File(bytes, "application/msi", "download.msi");
}
Try using binary encoding and content-type application/msi instead of text/plain - it's not ASCII or text content so you're mangling the file.