Is there a way to add metadata (such as keywords) to several png images using php? I have stored the images in my database, and I want to do the same with their corresponding keywords, but I haven't found any helpful suggestions using php yet. Thanks
image.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>Upload Images</title>
</head>
<body>
<form action="tags.php" method="POST" enctype="multipart/form-data" >
<p>Select Image (one or multiple):</p>
<input type="hidden" name="MAX_FILE_SIZE" value="536870912"/>
<input type="file" name="image[]" accept="image/png" accept="image/jpg" accept="image/jpeg" accept="image/gif" multiple="multiple" />
<input type="submit" value="Upload file" name="submit" />
</form>
</body>
</html>
tags.php (Raptor's answer)
<?php
include('../config.php');
$image = new Imagick();
$image->readImage("C:/xampp/htdocs/cmanager/uploads");
$image->setImageProperty('keywords', 'Imagick');
print($image->getImageProperty('keywords'));
You need ImageMagick's setImageProperty() help to achieve your goal.
<?php
$image = new Imagick();
$image->newImage(300, 200, "black"); // or load your PNG into Imagick
$image->setImageProperty('keywords', 'Imagick');
echo $image->getImageProperty('keywords');
?>
Require PHP to compile against ImageMagick 6.3.2+.
Alternatively, you can parse the PNG's metadata with the codes shown here. Try it out.
Last, if you intend to edit EXIF data instead, you can use the EXIF functions.
Also, you can set PNG metadata in pure PHP (example is about how to set a pHYs chunk).
Related
noob programer here. I'm doing a form and my teacher asked me to upload an image from any location of my computer and save it in a specific directory(also of my commputer). The code that i have only works if the image is in the same location as my script. Hope you can help me.
Note: Also i have to save it in the database because i'm going to use it to make a pdf.
HTML:
<html>
<head>
</head>
<form method="post" action="IConductores.php" >
<p></p>
<label>Foto</label>
<input type="file" id="Foto" name="Foto">
<input type="submit" id="Enviar" name="Enviar">
</form>
</html>
IConductores.php:
<?php
$Rfc = $_POST['Rfc'];
$Foto = $_POST['Foto'];
$SQL = "INSERT INTO Conductores VALUES ('$Rfc', '$Foto');";
$destdir = 'ImagenesPerfil/'; // path destination
$img=file_get_contents($Foto);
file_put_contents($destdir.substr($Foto, strrpos($Foto,'/')), $img);
add enctype="multipart/form-data" in your form tag
<form method="post" action="IConductores.php" enctype="multipart/form-data">
Uploaded file's name will be in $_FILES["Foto"]["name"]
And uploaded file location will be $_FILES["Foto"]["tmp_name"]
You need to use move_uploaded_file function like this
move_uploaded_file($_FILES["Foto"]["tmp_name"], $destdir.$_FILES["Foto"]["name"])
I have recently been working on a project that uses a bit of PHP. I don't know whether my question is obvious to those who have loads of experience, but here goes.
I don't know how to get a response from an upload PHP I created. If I have a form, like so...
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<label>Select image to upload:</label>
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
...and I have a PHP script that uploads these images to Cloudinary...
<?php
// Cloudinary init
require 'Cloudinary.php';
require 'Uploader.php';
require 'Api.php';
\Cloudinary::config(array(
"cloud_name" => "(cloud name)",
"api_key" => "(my key)",
"api_secret" => "(secret here)"
));
// Uploads images to Cloudinary
\Cloudinary\Uploader::upload($_FILES["fileToUpload"]["tmp_name"]);
?>
...how can I make it so that when submitted, it adds the value of the photo's URL (which is stored in a hash) to a hidden input in another form? Thanks so much.
P.S. Sorry for asking such n00b-y questions! (I'm new here)
First, make sure the session has been started. This allows you to send data over the server with post and files.
session_start()
Then you can access your inputs by name using the post and file functions.
# form.php
<?php session_start() ?>
<form action="after_form.php" method="POST" enctype="multipart/form-data">
<input type="text" name="text-input" value="Moon Text" />
<input type="hidden" name="some-input" value="xyyz" />
<input type="submit" />
</form>
Then on your next page, once the form has been submitted,
# after_form.php
echo $_POST['text-input']; //prints "Moon Text"
echo $_POST['some-input']; //prints "xyyz"
Usually you would save these data somewhere though.
If on this same after_form.php page you have a new hidden input, you could do something like
<input type="hidden" name="file-path" <?php echo 'value="'.$_POST['data'].'"';?> />
Hi im trying to upload an image to a database using php but every time i press the submit button i get the error
accept-file.php was not found
i dont see anywhere in my code where it will be directing to that is there something im missing?
<?php
session_start();
$link = mysqli_connect("localhost","root","","pictureupload");
if(isset($_POST['submit'])){
$imagename=$_FILES["iamge"]["name"];
$imagetmp=addslashes (file_get_contents($_FILES['image']['tmp_name']));
$insert_image="INSERT INTO images VALUES('$imagetmp','$imagename')";
mysqli_query($link,$insert_image);
}
?>
<!DOCTYPE html>
<html>
<head>
<Title>HomePage</Title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form action="accept-file.php" method="post" enctype="multipart/form-data">
Your Image: <input type="file" name="image" size="25" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
change your form tag to
<form action="?"
Your form has "accept-file.php" set as action:
<form action="accept-file.php" method="post" enctype="multipart/form-data">
This is where the form data will be sent to via the set method (POST in this case) and using the given encoding type.
After you click on "submit" your browser will call this script, which in your case does not exist. Therefore your webserver will return the error message instead of handling the upload.
To make it work you need to change the action to the filename of your script, which you have posted above.
Can someone please explain this code, i am following a very good book that was recommended to me and I have typed the code exactly as it is in the book. it displays the code instead of out, I am not sure what is wrong, the code is from a book called php solutions
<?php
// set the max upload size in bytes
$max = 51200;
if(isset($_POST['upload'])){
// define the path to the upload folder
$destination = 'C:\upload_test';
// move the file to the uplaod folder and rename it
move_uploaded_file($_FILES['image']
['tmp_name'], $destination.$_FILES['image']['setara']);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mult</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<form action="" method="post" enctype="mutipar/form-data" id="uploadImage">
<p>
<label for="image">Upload image:</label>
<input type="hidden"name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
<input type="file" name="image" id="image">
</p>
<p>
<input type="submit" name="upload" id="upload" value="Upload">
</p>
</form>
</body>
</html>
This is surely because you are writing PHP code in .html or .htm extension file try putting the code with .php extension file. It will resolve error.
I'm trying to upload some videos using PHP.
But I can't get them into any folder.
I don't get errors, so I don't know where to start.
My code:
<?php
if(isset($_FILES['files']))
{
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
move_uploaded_file($tmp_name, "upload/{$_FILES['files']['name'][$key]}");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Uploading videos</title>
</head>
<body>
<div>
<form action="" method="post" enctype="multipart/form-data">
<p>
<input type="file" name="files[]" multiple="multiple" min="1" max="9999" />
<input type="submit" value="Upload" />
</p>
</form>
</div>
</body>
</html>
I'm trying to upload, .webm, .ogv and .mp4
The files aren't that big, they're just 5MB or something.
First I got this error in Apache log: POST Content-Length of 15236606 bytes exceeds the limit of 8388608. So I changed that limit from 8MB to 80MB and now that error is gone, but the files aren't uploaded yet. And there are no errors anymore.
When I try to send some images, I get them. Probably there is something not handled correctly. But I don't know what.
Thanks in advance for the help ;)
Bjorn
You'll want to up the following settings:
post_max_size
upload_max_filesize
memory_limit
Also set_time_limit to something high as well.