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.
Related
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.
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).
This question already has answers here:
Why would $_FILES be empty when uploading files to PHP?
(22 answers)
Closed 8 years ago.
Regarding this ...... question but......... still learning :3
so i have a php file lets say called x.php and all working i would like to add uploader so people can upload txt files ....... but i dnt want to have another file which is uploader.php
Thnx in advance......
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<center>
upload ur CV.<br>
<form action="same.php" method="post"><br>
<input type="file" name="uploadFile">
<input type="submit" value="Upload Wordlist">
</form>
</body>
</html>
</center>
<?php
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}")
?>
Your form lacks "enctype="multipart/form-data" in
<form action="same.php" method="post"> which should read like this
<form action="same.php" method="post "enctype="multipart/form-data">
This is an essential part of uploading files.
Consult the manuals:
http://php.net/manual/en/function.move-uploaded-file.php
http://php.net/manual/en/features.file-upload.post-method.php
Plus, make sure that the folder is writeable and with proper permissions set.
Edit:
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<center>
upload ur CV.<br>
<form action="" method="post" enctype="multipart/form-data"><br>
<input type="file" name="uploadFile">
<input type="submit" name = "submit" value="Upload Wordlist">
</form>
</body>
</html>
</center>
<?php
if(isset($_POST['submit'])){
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}");
}
?>
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 require a file upload in a form, but cannot get it to work. Any ideas? I'd rather echo the php error on the page vs. a javascript popup. Thanks for taking a look:
<?php
// initialize $file1
$file1 = $_POST['file1'];
// check upload of $file1
if ($file1 == '' ) {
$error = "Please upload an image";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Require upload of an file</title>
</head>
<body>
<?php if ($error) {echo $error;} ?>
<br /><br /><br />
<form id="form1" name="form1" method="post" action="nextpage.php">
<input type="file" size="8" name="file1" />
<input name="Submit" type="Submit" />
</form>
</body>
</html>
See this tutorial it have all that you need.
To sum up:
Use enctype="multipart/form-data" and method="POST" in the <form> tag.
In PHP use $_FILES['uploadedfile']['name'] to read original name ("uploadedfile" is the name of your file input - "file1" in your example).
In PHP use $_FILES['uploadedfile']['tmp_name'] to read server side temp file name.
In PHP use $_FILES['uploadedfile']['error'] to get the error (if any) see there for possible codes.
Also see the PHP manual for more info.
In your exemple use this form instead:
<form id="form1" name="form1" method="post" action="nextpage.php" enctype="multipart/form-data">
<input type="file" size="8" name="file1" />
<input name="Submit" type="Submit" />
</form>
In "nextpage.php":
//Use $_FILES['file1'] to check the file upload...
print_r($_FILES['file1']);