Axis webcam http upload to php - php

Hi all i'm working on an axis p1343.
I tested the ftp upload succesfully.
Now i need to work with http upload to handle images seen that i do not need to keep ol images. So i'm writing a php script to hande the image buffer from that web cam.
After some work i realized that the cam was not sending anything.
So i created e really basic script to just test the jpg stream.
I receive a request with no data inside.
Does anyone know how that camera send the stream in the HU (Httpp Upload) mode ?
Thanks.

SOLVED!
Solution
to download data sent from the cam just use file_get_contents("php://input") so u can access the data stream a retrieve the data that cam sends as an attachment to the request.
This happens because the axis webcam use to send file as an attachment to the request simulating a "download link" request in a browser.
So to catch up those damn bits u have to read the php://input stream ....
It took some time time to figure out this workaround ... hope this will help you.

<?php
file_put_contents('image.jpg', file_get_contents('php://input'));
?>

Related

Get file contents after pageload

I have an external resource for my images let's say https://api.domain.com/api/downloads/{file_id}. The file gets downloaded after I visit that page. In this case I want to know the mimetype of the file. file_get_contents() doesn't work because the file is downloaded after I visit the page.
This means that I get HTML as output when I dump the result of file_get_contents(). I don't have any hold on how images are served to my application. So I guess I have to find a solution for this problem.
Is there a way to get the mimetype of a file after the page is loaded and it downloaded the file? If something I just wrote is not clear enough please let me know then I try to explain it further. Thanks in advance.
Some more detailed information:
I am currently creating an EML export from data from an external API from Genesys. This is pure PHP and thus I can’t make use of any client-side code like Javascript. The inline images in the body don’t show on in the EML export email body. I think this is because Genesys saves those images somewhere on their side. The image is not directly available from the URL they gave to me, because when I visit that page the page downloads a file but it is not directly served on that page.
To show the images inside the email body I want to encode them to base64 and change the src of the image to the base64 encoded image. To do so I need to know the filetype which I can’t get as described above.
Did you try with the onload property on the <img /> tag ?
<img src="w3html.gif" onload="loadImage()" width="100" height="132">
<script>
function loadImage() {
alert("Image is loaded");
}
</script>
https://www.w3schools.com/tags/ev_onload.asp
You will need to use javascript as the image is on a remote server and loaded on client side

WinINET and PHP php://input POST read

I have a weird problem. I want to upload some data with WinInet to a PHP script.
When I upload the data at once with HttpSendRequest(), then PHP reads the uploaded data correctly, e.g.
$entityBody = file_get_contents('php://input');
When I upload the data in parts with HttpSendRequestEx() and InternetWriteFile() , then the same data is uploaded, but PHP fails to read the input (empty).
What could be wrong?
Is the PHP script "called" before the entire data is uploaded?
If so, how do I get the data?
Found it, Content-Length header was missing.

How to paste image in chrome, then upload it to a server with PHP

I actually want to upload an image to a server.
To achieve this, i want the user just paste the image into chrome (the image is a print screen in fact), and then i post the stream to a php page, convert the stream as an image, and then upload it.
How can i achieve this web application ?
Today i have develop some differents parts :
I used this script, and i create the Upload.php page which gets the post variable and try to Create and image.
The problem i have, is that when i post the data, i only get a blob. I would like to get a base64 stream.
Can you help me ?
Thanks in advance.
I'm not sure why you are specifically looking for a "base 64 stream". If you are sending the Blob to your server via ajax, as far as your server is concerned, it's a file. Treat it no different than any other upload server-side. A Blob is a File without a name property. That's perhaps a bit overly-simplistic, but my point is that, again, this is really nothing more than a file as far as your server knows.
Assuming you are sending a multipart-encoded request, I'd like to point out that most user agents will set the filename property of the item's Content-Disposition header in the request to "blob" when the item you are uploading is a Blob instead of a file. It is possible to change this value in some browsers via the 3rd argument in FormData's append method, but I wouldn't rely on this just yet.
Also note that, if you are interested in a library that handles all of this already, I maintain, Fine Uploader which natively supports uploading images via paste in Chrome.
To answer this old question: Posting an image from clipboard with chrome is pretty much the same as posting a dropped file - except that the image/blob doesn't have the properties "name" and "lastModified".
var entry = items[i].webkitGetAsEntry();
if (!entry) entry = items[i].getAsFile();
if (entry instanceof Blob) /** CHROME pastet Bilder als Blob **/
{
entry.isFile = true;
entry.lastModifiedDate = new Date();
entry.name = ""+new Date().getTime()+"."+entry.type.split('/')[1];
}
if (entry.isFile)
{
//handle dropped file
}

listening to events on a website using php and/ javascript

I am looking to see if such a scenario is possible -
My website hosts couple of mp3 files. The URL would look like www.abc.com/.mp3 .
Assume that I get an incoming request from a user on iOS/android, using his browser to access my mp3 link above
My question is, can i listen to the event (that of my website mp3 being accessed) and then send send another mp3 to the user?
I am looking at using PHP and javascript, maybe, to do this. Please direct me on the approach to do this.
If you want to use php or javascript as said in your question, I can imagine two solutions for you problem on client side (javascript) or server side (php) :
On client side, using javascript, you can wrap the call to the mp3 in a javascript function (maybe by ajax). This function will check the browser and depending on it get the proper mp3
On server side, using php, you may wrap the mp3 query in a PHP script, say getmp3.php?file=xxx.mp3. Your client page will not get the mp3 directly but ask it to this php script. This script will check User Agent and send the mp3 with something like :
// Get the asked mp3
$askedfile = _GET['file'];
// Get browser info
$browser = get_browser(null);
// Put filename to the proper mp3 file depending on the browser
$filename = ...;
// Put the proper content/type :
header('Content-Type: audio/mp3');
header('Content-Disposition: attachment; filename="$askedfile"');
header('Content-Length: '.filesize($file));
// Send the mp3
readfile($filename);

php download does not embed swf

I have a PHP file that sends SWF flash for client , the flash downloads but does not embed in the HTML .
Any suggestions ?
Thanks
Edit :
a normal flash file (x.swf) is embeded into the browser normally , but the downloaded one using the php file (download.php?id=1) initiates a download and does not embed and is not corrupted , i think it is a headers problem , what is the MIME type for swf ??? can't find it !
Download headers were sent or MIME type is not recognized by the browser, maybe flash player is not installed. Posting code would explain everything.
Try SWFObject, it is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file. http://code.google.com/p/swfobject/

Categories