PHP Upload Video - php

I have been trying to upload an image and video and update data at the same time, I can upload the image, but it wont upload when I am also uploading a video and the data gets updated but my video will not upload. I've been trying to get the video to upload for weeks with no success... This is what I've tried:
I've tried adding MIME Types to my .htaccess file
AddType video/avi .avi
AddType video/quicktime .mov
AddType video/mpeg .mpeg .mpg
AddType video/mp4 .mp4
and I've tried changing my phpinfo settings in my php5.ini file
max_execution_time = 3000
upload_max_filesize = 50MB
Here is the PHP upload code
if (($_FILES["image"]["type"] == "image/jpeg") || ($_FILES["image"]["type"] == "image/pjpeg")){
if ($_FILES["image"]["error"] > 0){
echo $_FILES["image"]["error"];
}else{
move_uploaded_file($_FILES["image"]["tmp_name"],
"../upload/video_1_" . date("Ymd") . $_FILES["image"]["name"]);
move_uploaded_file($_FILES["video"]["tmp_name"],
"../upload/video_2_" . date("Ymd") . $_FILES["video"]["name"]);
$class->update($id, $title, $description, $image, $video);
echo "<div style='padding-left:50px'><strong>Updated!</strong></div>";
}
}else{
echo "<div style='padding-left:50px'><strong>Invalid Image!</strong></div>";
}
I ran a print_r on $_FILES and it returned an empty array
My Video size is 40.9MB
Any help or a point in the right direction would be appreciated,
Thanks in advanced,
J
This is my form
<form action="Videos.php?action=updatesubmit" method="post" enctype="multipart/form-data">
<input type="hidden" value="<?php echo $array['id']; ?>" name="id" />
<p>
<label for="name" style="vertical-align:top;">Title</label>
<input type="text" name="title" id="title" value="<?php echo $array['title']; ?>" />
</p>
<p>
<label for="description" style="vertical-align:top;">Description</label>
<textarea name="description" id="description" cols="70" rows="20"><?php echo $array['description']; ?></textarea>
</p>
<p>
<label for="image">Image</label>
<input type="file" name="image" id="image" value="<?php echo $array['image']; ?>" />
</p>
<p>
<label for="video">Video</label>
<input type="file" name="video" id="video" value="<?php echo $array['video']; ?>" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Update" />
</p>
</form>

If $_FILES is empty and you're not getting an error message when you upload, chances are you forgot to set enctype="multipart/form-data" in the <form> tag.

Take a look at web server error_log and access_log to see what happens. Is the file actually uploaded or not.

Related

Image Upload Not Working, Receiving No Errors

Here's my HTML form:
<form class="plist" action="build/build.php" method="_POST" enctype="multipart/form-data">
<label>Package Name: </label>
<input type="text" name="packageName">
<br />
<br />
<label>Package Description: </label>
<textarea rows="4" cols="20" type="text" name="packageDescription"></textarea>
<br />
<br />
<label>Website: </label>
<input type="text" name="packageWebsite">
<br />
<br />
<label>Contact: </label>
<input type="text" name="packageContact">
<br />
<br />
<label>Price: </label>
<input type="text" name="packagePrice">
<br />
<br />
<label>Screenshots: </label>
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="packageScreenshots" id="packageScreenshots">
<br />
<br />
<button type="submit" name="submit" value="submit">Build</button>
</form>
and build.php:
if($_SERVER['REQUEST_METHOD'] == 'POST' && $_FILES['packageScreenshots']['error'] == 'UPLOAD_ERR_OK'){
$uploaddir = '/zips/uploads/';
$uploadfile = $uploaddir . basename($_FILES['packageScreenshots']['name']);
list($width, $height, $type, $attr) = getimagesize($_FILES['packageScreenshots']['tmp_name']);
if (move_uploaded_file($_FILES['packageScreenshots']['tmp_name'], $uploadfile)) {
echo "File was successfully uploaded.\n";
} else {
echo "Hmm...";
}
};
// Create the zipped folder using ZipArchive()
$zip = new ZipArchive;
$full = $zip->open("/zips/$packageName.zip", ZipArchive::CREATE);
$zip->addFile('/zips/uploads/install.plist', 'install.plist');
$zip->addFile('/zips/uploads/google.png', 'google.png');
$zip->close();
The ZipArchive() function works great, there's stuff above what I showed in build.php where install.plist is created, that works fine, the .plist is created under the correct directory and compiled into the zip. When selecting and image for upload, the image isn't found under /zips/uploads/ like it should be. Haven't been able to get it to work on either localhost or on my server. Tried PHP 5.4 through 7.1 (GoDaddy), with the zip library enabled. The directories have correct permissions as well.
Try changing _POST to POST. :)

Upload files with multiple inputs

I have a form where i want to upload files with multiple inputs.My form looks like:
<form action="" method="post">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
I do not know how to process this form..
You form doesn't work until you don't include 'enctype="multipart/form-data"', because it is necessary to use input type file.
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
Now browse the file and submit the form. You will get all file data inside $_FILES. so to check what you get inside the file data, you can use :
echo '<pre>';
print_r($_FILES)
I'm not sure whether you have gone through the tutorials before, however below is the code which will help you to process it.
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
If you upload the file, you can get the files from,
$_FILES global array, i.e. $_FILES['tax'] and $_FILES['ta'].
More info can be found on php.net
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="tax" />
<input type="file" name="ta" />
<input type="submit" name="submit" />
</form>
<?php
//print_r($_POST);
if(isset($_POST['submit'])){
$name = $_FILES['tax']['name'];
$name1 = $_FILES['ta']['name'];
$temp_name = $_FILES['tax']['tmp_name'];
$temp_name1 = $_FILES['ta']['tmp_name'];
var_dump($_FILES);
if(isset($name)){
if(!empty($name)){
var_dump($_FILES);
$location = 'images/'.$name;
if(move_uploaded_file($temp_name, $location)){
echo 'File uploaded successfully';
}
}
} else {
echo 'You should select a file to upload !!';
}
if(isset($name1)){
if(!empty($name1)){
var_dump($_FILES);
$location = 'images/'.$name1;
if(move_uploaded_file($temp_name1, $location)){
echo 'File uploaded successfully';
}
}
} else {
echo 'You should select a file to upload !!';
}
}
?>

Upload multiple image files and display on the next page. PHP

I am attempting to upload multiple images at once, and then on submit display those images on the page. This is going to be used with mPDF. I am using the examples in the manual at http://mpdf1.com/manual/index.php?tid=467
It has a text box and 1 image uploader, and displays what ever was in the text box and the image on the next page. How can I convert this to use multiple images?
Page 1:
<?php
$html = '
<html>
<body>
<form action="example_userinput2.php" method="post" enctype="multipart/form-data">
Enter text:
<br />
<textarea name="text" id="text"></textarea>
<br />
<label for="file">Choose Image to upload:</label> <input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
';
echo $html;
exit;
?>
Page 2: (also more specifically what I change the areas I marked ** **, after allowing multiple images.)
<?php
if (($_FILES["file"]["type"] == "image/gif" || $_FILES["file"]["type"] == "image/jpeg")
& $_FILES["file"]["size"] < 20000) {
// If the destination file already exists, it will be overwritten
move_uploaded_file($_FILES["file"]["tmp_name"], "../tmp/" . $_FILES["file"]["name"]);
}
else {
echo "Invalid file";
}
$html ='
<html>
<body>
<div>'.$_POST['text'].'</div>
**<img src="' ."../tmp/" . $_FILES["file"]["name"].'" />**
<form action="example_userinput3.php" method="post" enctype="multipart/form-data">
<textarea style="display:none" name="text" id="text">'.$_POST['text'].'</textarea>
**<input type="hidden" name="filename" id="filename" value="'. $_FILES["file"]**["name"].'" />
<input type="submit" name="submit" value="Create PDF file" />
</form>
</body>
</html>
';
echo $html;
exit;
?>
Page 3 goes to the mPDF generator so I can convert this to PDF for another project I have in mind.
Any help would be awesome.
From php manual, to find here: http://php.net/manual/en/features.file-upload.multiple.php
<form action="example_userinput2.php" method="post" enctype="multipart/form-data">
Send these files:<br />
<input name="userfile[]" type="file" /><br />
<input name="userfile[]" type="file" /><br />
<input type="submit" value="Send files" />
</form>
On page2, you can continue with a loop and handle those files at once:
foreach ($_FILES['array_of_files'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
var_dump($file);
}
You can do the same as with one file in the loop
You can have multiple <input type="file"> html elements set up on your page set up this way:
<input type="file" name="file[0]" />
<input type="file" name="file[1]" />
etc.
And then in PHP loop through them:
foreach($_FILES['file'] as $file){
//refer to everything as $file instead of $_FILES['file']
}
That should be enough to get you started.

File upload on another page

I have a form and the action of the form is submit.php, what I am trying to do on submit.php to upload a file image, but when I click submit and print_r $_FILE an empty array appears. What am I doing wrong? I dont want to upload the file on the same page as the form. Here is the form:
<form action="in-the-press-submit.php" method="post">
<p>
<label for="title">Title:</label>
<input type="input" name="title" id="title">
</p>
<p>
<label for="posted-on">Posted On:</label>
<input type="date" name="posted-on" id="posted-on">
</p>
<p>
<label for="description" style="vertical-align:top;">Description:</label>
<textarea rows="20" cols="70" name="description" id="description"></textarea>
</p>
<p>
<label for="image">Image:</label>
<input type="file" name="image" id="image">
</p>
<p>
<input type="submit" name="submit" id="submit">
</p>
</form>
and here is my code in the submit page:
<?php
if ($_FILES["file"]["error"] > 0) {
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],
"/image-test/" . $_FILES["file"]["name"]);
echo "Stored in: " . "/image-test/" . $_FILES["file"]["name"];
}
?>
Try this
<form action="in-the-press-submit.php" method="post" enctype="multipart/form-data">
Documentation : http://www.w3schools.com/php/php_file_upload.asp
You need enctype="multipart/form-data" in your form tag:
<form action="in-the-press-submit.php" method="post" enctype="multipart/form-data">
See the php manual on POST method uploads.
the reason that you need to include enctype=multipart/form-data in the form tag is :
application/x-www-form-urlencoded is the standard and default way to POST a form without attached files.
multipart/form-data is the standard way to POST a form with attached file(s) because this encoding allows entire files to be included in the data
In order to upload a file add
enctype = "multipart/form-data"
in form tag.

move_uploaded_file not working as it should

I've searched around but I can't find my issue. I have a simple script that uploads a file to the target-folder.
$target = "img/fotos-artikels/";
$target .= basename($_FILES["uploadBron"]["name"]);
if(move_uploaded_file($_FILES["uploadBron"]["tmpname"], $target)) {
echo "The file " . basename($_FILES["uploadBron"]["name"]) . " has been uploaded.";
} else {
echo " Sorry there was a problem";
}
And this is the form:
<form enctype="multipart/form-data" action="" method="post">
<label for="txtBronNaam">Naam:</label>
<input type="text" name="txtBronNaam" id="txtBronNaam" value="" /><br />
<label for="uploadBron">File:</label>
<input type="file" name="uploadBron" id="uploadBron" value="" /><br />
<input type="submit" name="" value="Voeg bron toe" />
</form>
Do I have to enable something in apache maybe?
tmpname should be tmp_name

Categories