i need your help please and i haven't found some answers for my problem.
I want to take a picture (or take it from the gallery) on the iphone/ipad and then encode the picture to a base64 string with php and send the base64 string to a webservice.
If i try it on the pc, everything is alright.
if i want to do this on the ipad, it seems like nothing or a incorrect base64 string is send to the webservice but i have no idea why or so?!
picture.php
<form action="picture.php?action=upload" method="post" enctype="multipart/form-data">
<input type="file" name="datei" accept="capture=camcorder">
<br/><br/>
<input type="submit" value="up">
</form>
<?
if(isset($_GET['action']))
{
$tmp_name = $_FILES["datei"]["tmp_name"];
$name = $_FILES["datei"]["name"];
$name = substr($name,0,-4);
$name.="_".time().".jpg";
move_uploaded_file($tmp_name, "upload/".$name);
$content = file_get_contents ( "upload/".$name );
$imageBase = base64_encode( $content );
$success = savePicture($imageBase);
}
function savePicture()
function savePicture($pic_base64)
{
ini_set("soap.wsdl_cache_enabled", "0");
$pageURL = 'http://....';
$page = new NTLMSoapClient($pageURL);
$params = array("pRecordID" => "1",
"pFieldID" => 70000,
"pUserID" => "153",
"pContent" => $pic_base64
);
$result = $page->SetBLOBValue($params);
if($result->return_value != "ERROR")
{
return true;
}
else
{
return false;
}
}
Any Ideas why this didn't work on ipad/iphone?
i hope anybody could help me.
I think that the iPhone/iPad has some problems with capture=camcorder.
Please try this:
<input type="file" name="datei" accept="image/*;capture=camera">
instead of
<input type="file" name="datei" accept="capture=camcorder">
For more information check this:
http://www.html5rocks.com/de/tutorials/getusermedia/intro/
SOLVED
The Problem is that the SOAP Service had a Max-Size for the Files for 1MB!
That was the Problem why i can't upload Base64 Strings who are bigger than 1MB!
Now we increase the Max-Size for Files to 10MB and now it works!
And that was the reason why i cant upload some pictures because some pictures was bigger than 1mb in the base64 string.
Thx for help to everybody!
Related
I want to post multiple images by posting the url's but I don't know how to do this because I am new to PHP.
<?PHP
if(isset($_POST['post_image']))
{
$image_url=$_POST['image_path'];
$data = file_get_contents($image_url);
$new = '../images/myimage.jpg';
$upload =file_put_contents($new, $data);
if($upload) {
echo "<img src='../images/myimage.jpg'>";
}else{
echo "Please upload only image files";
}
}
?>
The problem with your script is, that you are not saving the file anywhere. So you have no access to it when trying to return it to the client.
In order to save an image using a POST you need to make sure you have set the following enctype inside your form.
<form action="upload.php" method="post" enctype="multipart/form-data">
Then you can use this function to save the img
move_uploaded_file($_FILES["myImg"], "/path/to/imgDir")
And later show it to the client using:
echo "<img src='/path/to/imgDir/myImg'>"
For more information about the topic i advice you to consult the following URL
https://www.w3schools.com/php/php_file_upload.asp
Can someone here can help me on my problem ? I have this code on displaying output of pdf file on web using pdftotext
include ( 'PdfToText-master/PdfToText.phpclass' ) ;
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="pdf_file" multiple="multiple">
<input type="submit" name="SubmitButton"/>
</form>
if(isset($_POST['SubmitButton'])){
$pdf = new PdfToText ($_FILES['pdf_file']['tmp_name']) ;
text = $pdf -> Text;
echo $text;
}
it works fine, But what im trying is to upload multiple files and display it on web all the files uploaded. I can't find any solution. Can you help me guys ? :(
PS: sorry my english is not that good. THank youuu!
where you upload multiple file. you will get the files in array.
Therefore, you need to loop over the tmp files
function show_pdf_text($file){
$pdf = new PdfToText ($file) ;
$text = $pdf->Text;
echo $text;
}
if(isset($_POST['SubmitButton'])){
if(is_array($_FILES['pdf_file']['tmp_name'])){
foreach($_FILES['pdf_file']['tmp_name'] as $temp){
show_pdf_text($temp);
}
}else show_pdf_text($_FILES['pdf_file']['tmp_name']);
}
I'm creating a website where users can uploads some images, URL images are saved into json and inserted into database so when I select all of the rows in the table it gives me something this.
{
"sroxrafm72pgipmpa4nz":
"http:\/\/res.cloudinary.com\/dok4nvr2e\/image\/upload\/v1444610510\/sroxrafm72pgipmpa4nz.jpg"
},
{
"egrrhg4umqgyjoltxrky":
"http:\/\/res.cloudinary.com\/dok4nvr2e\/image\/upload\/v1444610511\/egrrhg4umqgyjoltxrky.jpg"
},
{
"rfurg40o5af2h6s55thb":
"http:\/\/res.cloudinary.com\/dok4nvr2e\/image\/upload\/v1444610511\/rfurg40o5af2h6s55thb.jpg"
}
I need to decode it with twig to get the url of each id to display the images, but I just can't figure out to do this. I hope you guys can help me.
I'd say this is a clone of: Decoding JSON in Twig
What might be easier is to base64 encode the images and store the string inside of the database. I use the following:
In HTML:
<form method="post" action="upload.php" enctype="multipart/form-data">
<input type="file" name="image" />
</form>
upload.php:
function getImageBase64($image_path) {
$image = imagecreatefromfile($image_path);
ob_start();
imagepng($image);
$contents = ob_get_contents();
ob_end_clean();
$image_string = 'data:image/png;base64,' . base64_encode($contents);
imagedestroy($image);
return $image_string;
}
if (getimagesize($_FILES["image"]["tmp_name"]) !== false) {
$image = getImageBase64($_FILES["image"]["tmp_name"]);
//Add to database...
}
I'm trying to implement a small update profile pic form.
<form method="post" action="<?php echo $filename;?>" name="change_picture_form" id="change_picture_form" enctype="multipart/form-data">
<input type="hidden" name="action" value="change_picture" />
<input type="file" name="new_user_picture">
<input type="submit" class="submitButton" value="Save Changes"/>
</form>
The target php file has the following code:
echo $_FILES['new_user_picture']['size']." ";
echo $_FILES['new_user_picture']['tmp_name']." ";
echo $_FILES['new_user_picture']['name']." ";
echo $_FILES['new_user_picture']['error']." ";
echo $_FILES['new_user_picture']['type']." ";
$picture_uploaded = $_FILES["new_user_picture"]["tmp_name"];
if( is_uploaded_file( $picture_uploaded ) ) {
$imagesize = getimagesize( $picture_uploaded );
switch( $imagesize[2] ) {
case IMAGETYPE_PNG:
$extension = '.png';
echo "<script>console.log('Reached here!!')</script>";
try {
$image_original = imagecreatefrompng( $picture_uploaded );
if (!$image_original)
echo '<script>console.log("not image original")</script>';
} catch(Exception $e) {
echo "<script>console.log('Error!!')</script>";
}
break;
case IMAGETYPE_JPEG: ....
...
}
}
Here, I have similar code for many image types. I tested this code by trying to uploading a png image. The first 5 echo statements display expected results - the size, error value of zero, the name, the type and the temp name.
I get "Reached here!!" on my console.
imagecreatefrompng, however, seems to crash silently. Try-catch somehow doesn't seem to catch the error.
Help? Thanks!
I haven't handled file uploads in PHP in forever, but is it possible that this line:
$picture_uploaded = $_FILES["new_user_picture"]["tmp_name"]
should be
$picture_uploaded = $_FILES["new_user_picture"] ?
The first line, as is, should be getting you the uploaded file's file name, whereas the second line (the edited line above) should be a reference to the file itself.
HTH.
EDIT: Well, seeing as how my answer is incorrect... does this help? http://www.php.net/manual/en/function.imagecreatefromstring.php
. There's a helper function in the user notes/comments that might simplify what you're doing
I'm trying to make an image upload form for twitter to change avatar. Twitter says the image has to be base 64 encoded before I upload it. So here's a sample
https://dev.twitter.com/docs/api/1/post/account/update_profile_image
How can I do this so far I've been getting errors
PHP Code:
<?php // process form data
if ($_POST['image']){
// post profile update
$post_data = array(
"image" => $_POST['image']
);
$post_data = base64_encode($post_data);
echo $post_data;
}
else{
echo
" <form action='post.php' method='POST' enctype='multipart/form-data'>
<br><input type='hidden' name='image' value='update_profile_image'>
<input type='file' name='image' size='30'/><br>
<input type='submit' value='Upload' class='button'/>
</form>";}
?>
Please help
From the looks of this, you aren't retrieving the image from the POST at all. The image itself will be available in $_FILES
// See what's in $_FILES
var_dump($_FILES);
// You need the temporary name of your image from $_FILES
$filedata = file_get_contents($_FILES['image']['tmp_name']);
$post_data = base64_encode($filedata);
// Now you should have a base64 ascii string
echo $post_data;
This should do it.
Move the uploaded file to a directory because you cannot get required results by encrypting the [tmp_name]
if ($_FILES['image']){
move_uploaded_file($_FILES["image"]["tmp_name"], "path" .basename($_FILES["image"]["name"]));
$meh = file_get_contents("path/" .basename($_FILES["image"]["name"]));
$results = base64_encode($meh);
}