Image Upload Not Working, Receiving No Errors - php

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. :)

Related

BulletProof's image class not uploading at all

So in BulletProof's documentation, I follow what I had to do and the image doesn't even get to "echo" phase #2.
https://github.com/samayo/bulletproof/blob/master/README.md
if (isset($_POST['post_blog_submit'])) {
$image = new Bulletproof\Image($_FILES);
$title = $filter->input("string", $_POST['title']);
$body = $filter->input("string", $_POST['body']);
$image->setName('test')
->setMime(array('jpg'))
->setLocation('/data/gallery', 777)
->setDimension(250, 250)
->setSize(100, 10000000);
if($image['bthumb']){
echo 'Phase #2';
if($image->upload()){
echo $image->getName(); // samayo
echo $image->getMime(); // gif
echo $image->getLocation(); // avatars
echo $image->getFullPath(); // avatars/samayo.gif
echo 'uploaded';
} else {
echo $image['error'];
}
}
echo $image['error'];
}
This is my PHP code, which does exactly what README.MD stated for me to do.
<form name="post_blog" method="post" enctype="multipart/form-data">
<label for="title">Blog Title</label>
<input class="form-control" type="text" name="title" placeholder="Blog Title" required /> <br/>
<label for="body">Blog Body</label>
<textarea class="form-control" name="body" placeholder="Place your text ..." required> </textarea> <br/>
<label for="bthumb">Blog Thumbnail</label>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
<input type="file" name="bthumb" /> <br/>
<div class="pull-right">
<input type="hidden" name="post_blog_submit" value="1" />
<input type="submit" class="btn btn-danger" value="Submit!" />
</div>
</form>
I don't know what is possibly wrong, the form part of it looks correct and the backend looks correct. But it isn't even detecting the input itself.

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.

Updating image into databse using php and mysql

i want to store an image in database not by inserting but by updating (by using UPDATE query).
Everything else is updated successfully but its not storing image. I'm using medium blob data type to store image.
Here is my code:
update-profile.php:
<form id="form" method="post" action="update-profile-action.php" enctype="multipart/form-data">
<label for="Fname">First Name:</label> <input type="text" id="Fname" class="text" value="<?php echo $firstname; ?>" name="Fname" /> <br /><br />
<label for="Lname">Last Name:</label> <input type="text" id="Lname" class="text" value="<?php echo $lastname; ?>" name="Lname" /><br /> <br />
<?php
if ($_SESSION["type"]=="T")
{
?>
<label>Profile Image:</label> <input type="file" name="image" value="" /><br /> <br />
<label>Qualification:</label><textarea name="qualification" class="text" id="qualification"><?php echo $qualification;?></textarea><br /><br />
<label>Education & Teaching History:</label> <textarea name="briefintro" class="text" id="intro"><?php echo $briefintro; ?></textarea><br /><br />
<?php
}
?>
<input type="submit" class="mybutton" value="Update Profile" />
</form>
update-profile-action.php:
<?php include("../includes/config.php");?>
<?php
$Fname=$_POST["Fname"];
$Lname=$_POST["Lname"];
$image=$_POST["profileimg"];
$briefintro=$_POST["briefintro"];
$qualification=$_POST["qualification"];
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db($dbname, $con);
$query=("UPDATE accounts SET firstname='".$Fname."' , lastname='".$Lname."' , profileimg='".$image."' , briefintro='".$briefintro."', qualification='".$qualification."' WHERE id=".$_SESSION['id']);
$result = mysql_query($query);
header("Location: update-profile.php?status=3");
mysql_close($con);
?>
i copied only the related data from update-profile.php to making it more easy to read :)
any kind of help will be appreciated :)
Two problems:
You do not have an id for the input tag for the file. You need to change <input type="file" name="image" value="" /> to <input type="file" name="image" value="" id = "profileimage" />
Secondly you access files not via $_POST but rather via $_FILES.

PHP Upload Video

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.

warning in mkdir and how to display images from the directory created

My program is supposed to create a folder for the uploaded images on the directory but gives this warning:
mkdir() [function.mkdir]: File exists in C:\XAMP\xampp\htdocs\gallery\uploader3.php on line 26
Here is the code:
<html>
<head>
<title> Sample1 - File Upload on Directory </title>
</head>
<body>
<div align="center">
<form action="uploader3.php" method="post" enctype="multipart/form-data" >
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Create an Album (limited to 10 images): <br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<input type="file" name="uploadedfile[]" /><br />
<br />
<input type="submit" value="Upload File" />
</form>
</div>
<?php
$target_path = "uploads1/";
if(!mkdir($target_path))
{
die('Failed to create folders...');
}
else
{
for($count = 0; $count < count($_FILES['uploadedfile']); $count++)
{
$target_path = $target_path . basename( $_FILES['uploadedfile']['name'][$count]);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$count], $target_path))
{
echo "The file ". basename( $_FILES['uploadedfile']['name'][$count]).
" has been uploaded";
}
else{
echo "There was an error uploading the file, please try again!";
}
}
}
?>
</body>
</html>
Modify your codes below:
if(!mkdir($target_path))
{
die('Failed to create folders...');
}
to:
if(!file_exist($target_path)) {
if(!mkdir($target_path))
{
die('Failed to create folders...');
}
}
That will check the folder first, if it's already exist, no need to create it again.
for your 2nd question, you need to store the uploaded image names to somewhere ( i guess DB is a good choice), Then, you can show them anywhere you want.
Or you can use below codes to search in folder and display them:
$image_files = glob("uploads1/*.jpg");
foreach($image_files as $img) {
echo "<img src='".$img."' /><br/>";
}
You should check first that the directory does not already exist before attempting to create it
if (!file_exists($target_path))
mkdir($target_path);
if (file_exists($target_path))
{
// Further processing here
}
else
{
// Could not create directory
}

Categories