I have a php file upload in place in which the forms target is an iframe.
It uploads files less than 2mb fine. But anything larger it will not upload. I cant see any reason behind this in the code.
<div id="upload_wrapper">
<img src="../images/logo.png" alt="logo5" width="" height="" style="padding:0px;" />
<h3>Profile picture upload</h3>
<form id="upload" name="upload" enctype="multipart/form-data" method="post" action="index.php" target="upload_target">
<input name="folder" type="hidden" value="<?php echo $folder ?>" />
<input name="filename" type="hidden" value="<?php echo $filename ?>" />
<input name="uploaded_file" type="file" size="5120" id="uploaded_file" />
<input id="sent" name="sent" type="submit" value="Upload" />
</form>
</div>
<div id="loading" style="background:url(ajax-loader.gif) no-repeat left; height:50px; width:370px; display:none;">
<p style="margin-left:40px; padding-top:15px;">Uploading File... Please wait</p>
</div>
<div id="image_wrapper" style="display:none;"><p id="preview"></p></div>
<iframe id="upload_target" name="upload_target" style="width:10px; height:10px; display:none"></iframe>
</div>
And heres the php upload code
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$targetFolder = $_POST['folder'] . "/";
$filename2 = $_POST['filename'];
if (!is_dir($targetFolder))
{
mkdir($targetFolder, 0777);
}
$tempFile = $_FILES['uploaded_file']['tmp_name'];
$targetPath = dirname(__FILE__) . '/' . $targetFolder;
$targetFile = rtrim($targetPath,'/') . '/' . $_FILES['uploaded_file']['name'];
// Validate the file type
$fileTypes = array('jpg'); // File extensions
$fileParts = pathinfo($_FILES['uploaded_file']['name']);
if (in_array($fileParts['extension'],$fileTypes))
{
$uploadfile = $targetFolder. basename($filename2 .".".$fileParts['extension']);
move_uploaded_file($tempFile,$uploadfile);
$fileName = $uploadfile;
}
echo "<div id='filename'>$fileName</div>";
}
Maybe changing your php server's configuration would help (example for 10MB):
ini_set('upload_max_filesize', '10M');
make sure your php.ini configuration support large files. upload_max_filesize and post_max_size also you can change the configuration temporary using ini_set before you handle the upload process.
try this may be it would work put it in your code and then try
define ("MAX_SIZE","1000"); // put your max size value
$size=filesize($_FILES['uploaded_file']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}
or else you have to edit in php.ini found in document root/php/php.ini
You can change your server setting. Look for the php.ini file and search "upload_max_filesize"
Related
<?php
if (isset($_FILES['file']['name'])){
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$location = 'uploads/';
if (!empty($name)){
if(move_uploaded_file($tmp_name, $location.$name)){
echo 'Uploaded successful';
}
}else
echo 'Please select a file.';
}?>
<form action="upload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><br><br>
<input type="submit" value="Submit">
</form>
I am not getting any error but the move_uploaded_file() is not working. It displayed no result on the browser. I have the folder 'uploads/' inside my directory.
The problem is solved, the maximum file size for the file to be uploaded is 2MB. The file that I tried to upload exceed 0.1MB. Thank all of you.
i am able to display image on screen but i want to display the image using session.Please help me.
$_SESSION['user_name6'] = $_FILES["file"]["name"];
if(isset($_SESSION['user_name6']))
{
echo "<img src=<?php echo $_SESSION[user_name6]; ?> width=300 height=400
alt=Image path Invalid name=image />";
}
else
{
print "no pic here";
}
I do not know what you will actually do but this is the approach that best fits
when you put a file type in your form, you need to use the global variable Files
form.html
<form action="process.php" method="post" enctype="multipart/form-data">
<label for="picture">Picture:</label>
<input type="file" name="picture" id="picture"><br>
<input type="submit" name="submit" value="Upload">
</form>
process.php
<?php
session_start();
//make sure you have created the **upload** directory
$filename = $_FILES["picture"]["tmp_name"];
$destination = "upload/" . $_FILES["picture"]["name"];
move_uploaded_file($filename, $destination); //save uploaded picture in your directory
$_SESSION['user_name6'] = $destination;
header('Location: display_picture.php');
display_picture.php
<?php
session_start();
?>
<div>
<img src="<?php echo $_SESSION['user_name6']; ?>" alt="picture"/>
</div>
I'm having an issue with a file upload where it's not uploading. When uploading a 7mb video the $_FILES['video']['tmp_name'] is empty and when I upload a 15mb file the form doesn't actually "submit", really just refreshes.
Here is my code to handle the submission:
if(isset($_POST['submit'])){
$blah = "".$_FILES['video']['size']."";
var_dump($blah);
if( empty($_FILES['video']) && empty($_POST['create_video']) ){
echo "<div class='alert alert-danger' role='alert'><center><strong>Missing Fields:</strong> Please choose a video or request the ##### team create a video.</center></div>";
} else {
if( empty($_FILES['video']['name']) && $_POST['create_video'] == "true" ){
$_SESSION['create_video'] = protect($_POST['create_video']);
?>
<script type="text/javascript">
window.location = "NEXT_PAGE";
</script>
<?
exit();
}else{
//if all were filled in continue
$allowedExts = array("mp4", "MP4", "m4a");
$extension = pathinfo($_FILES['video']['name'], PATHINFO_EXTENSION);
if ( ($_FILES["video"]["size"] <= 15728640) && (in_array($extension, $allowedExts)) ) {
if ($_FILES["video"]["error"] > 0){
echo "Return Code: " . $_FILES["video"]["error"] . "<br />";
}else{
//Get the height and width of our video
//$getID3 = new getID3;
//$file = $getID3->analyze($_FILES["video"]["tmp_name"]);
//$width =$file['video']['resolution_x'];
//$height = $file['video']['resolution_y'];
$img = getimagesize($_FILES['video']['tmp_name']);
$width = $img[0];
$height = $img[1];
var_dump($width); var_dump($height);
if( ($height < 719) || ($width < 1279)){
echo "<div class='alert alert-danger' role='alert'><center><strong>Invalid file dimensions</strong> Please ensure your image is the correct size.</center></div>";
} else {
$ext = findexts ($_FILES["video"]["name"]);
$ran = rand ();
$file_name = $_FILES["video"]["name"] = "".$_SESSION['uid'] ."".$ran.".".$ext."";
if (file_exists("uploads/video_ads/".$_SESSION['uid']."_" . $_FILES["video"]["name"])){
echo $_FILES["video"]["name"] . " already exists. ";
}else{
move_uploaded_file($_FILES["video"]["tmp_name"],
"uploads/video_ads/".$_SESSION['uid']."_" . $_FILES["video"]["name"]);
//Save the link of our ad
$_SESSION['video'] = "####/uploads/video_ads/".$_SESSION['uid']."_" . $_FILES["video"]["name"]."";
$_SESSION['create_video'] = protect($_POST['create_video']);
?>
<script type="text/javascript">
window.location = "NEXT_PAGE";
</script>
<?
exit();
}
}
}
} else {
echo "<div class='alert alert-danger' role='alert'><center><strong>Invalid file type</strong> Please upload a video in MP4 format.</center></div>";
}
}
}
}
Here is my actual form:
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post" class="form-signin" role="form" enctype="multipart/form-data">
<br />
<input type="file" name="video" id="video" /><br />
<br />
<div class="row">
<div class="col-md-12">
<strong class="ad-header"
style="font-size: 150%; font-weight: bold;">Quick Tips:</strong>
</div>
</div>
<hr>
<h3 class="ad-sub-header" style="color: #559fd3; font-size: 150%;">Need
help to create engaging artwork for your brand?</h3>
<strong class="ad-header" style="font-size: 100%;">####
has the creative team to get it done for you</strong><br /> Only ##/hr -
3 revisions - Artwork is yours to keep. <br />
<br /> <input type="checkbox" name="create_video" value="true" />
I don't have an ad. Please create one. <br />
<br /> <input class="btn btn-lg btn-primary btn-block"
type="submit" name="submit" value="Continue To Step 5" />
</form>
The odds are your server does not accept uploads greater than 2M in size. You need to check phpinfo() (or php.ini if you have access to it) to see what your current limit is. If it is only 2M, or smaller than your upload size, you need to edit it to allow for bigger uploads. If you're on shared hosting you may be out of luck.
Try adjusting your php.ini with this settings:
php_value memory_limit 96M
php_value post_max_size 96M
php_value upload_max_filesize 96M
and ensure that the file_uploads setting is in On
For anyone who has this issue. I had to increase my post_max_size which was defaultly set to 8M.
I'm having problems with a file upload script for my site. I've copied a simple upload script, and I'm setting it up so that I can upload multiple files. I have to do this by first making one form for one file, then a copy of the form for the next one and so one. (I first set the page up with the "multiple" tag in the form, but then i discovered that the IE at work is version 8, and no flash. So I have to do it this way)
The scripts uploads ok. The problem is that the second file is called file1.jpgfile2.jpg, the third one file1.jpgfile2.jpgfile3.jpg and so on.
this is my form, followed by the code with form #2 File #2 and on goes through the same form:
<form method="post" enctype="multipart/form-data" action="rediger.php?choice=addpicturetoproc">
<input type="hidden" name="uploadpath" value="<? echo "Prosedyrer/$hovedkategori/$underkategori/$navn/$mappe_navn/" ?>">
Bildefil: <input type="file" name="fileup" value=""><br>
<input type="submit" name="submit" value="Upload">
</form>
<br>
<?
}
elseif ($choice=="addpicturetoproc")
{
$max_size = 2000; // maximum file size, in KiloBytes
$alwidth = 1900; // maximum allowed width, in pixels
$alheight = 1800; // maximum allowed height, in pixels
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png'); // allowed extensions
if(isset($_FILES['fileup']) && strlen($_FILES['fileup']['name']) > 1) {
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
// Checks if the file has allowed type, size, width and height (for images)
if(!in_array($type, $allowtype)) $err .= 'The file: <b>'. $_FILES['fileup']['name']. '</b> not has the allowed extension type.';
if($_FILES['fileup']['size'] > $max_size*1000) $err .= '<br/>Maximum file size must be: '. $max_size. ' KB.';
if(isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= '<br/>The maximum Width x Height must be: '. $alwidth. ' x '. $alheight;
// If no errors, upload the image, else, output the errors
if($err == '') {
if(move_uploaded_file($_FILES['fileup']['tmp_name'], $uploadpath)) {
echo '<h1>Filen: <b>'. basename( $_FILES['fileup']['name']). '</b> ble lastet opp!</h1>';
}
else echo '<b>Feil ved opplastning.</b>';
}
else echo $err;
}
?><p>Do you need another upload?</p>
<form method="post" enctype="multipart/form-data" action="rediger.php?choice=addpicturetoproc">
<input type="hidden" name="uploadpath" value="<? echo $uploadpath; ?>">
Bildefil: <input type="file" name="fileup" value="Sett inn bildefilen her"><br>
<input type="submit" name="submit" value="Last opp bildefil">
</form>
<br>
<form method="post" enctype="multipart/form-data" action="rediger.php?choice=menu">
<input type="submit" name="submit" value="Nei, jeg er ferdig">
</form>
I have tried using unset($fileup); before the second run, but still filename1.jpgfilename2.jpg.
Any obvious solutions?
I believe this is because you're appending to the $uploadpath
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']);
So the first file will be file1.jpg then the second file will be file1.jpgfile2.jpg and so on.
I would suggest setting the base upload path to a different variable and trying something like
$uploadpath = $baseuploadpath . basename( $_FILES['fileup']['name']);
Can anyone give me the html code for this php image upload script. I really need it please if anyone can help me on this I will be grateful to you.
Here is php code:
if(isset($_POST['upload'])) {
$allowed_filetypes = array('.jpg','.jpeg','.png','.gif');
$max_filesize = 10485760;
$upload_path = 'uploads/';
$description = $_POST['imgdesc'];
$filename = $_FILES['userfile']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) {
$query = "INSERT INTO uploads (name, description) VALUES ($filename, $description)";
mysql_query($query);
echo 'Your file upload was successful!';
} else {
echo 'There was an error during the file upload. Please try again.';
}
}
I came across this exact code a while back
Here you go for html
<form action="/script.php" method="post" enctype="multipart/form-data">
<input type="file" name="userfile"/>
<input type="text" name="imgdec">
<button name="upload" type="submit" value="Submit">
</form>
<form name="myFrm" id="myFrm" action="uraction" method="post" enctype="multipart/form-data" >
<label for="upload" >Select Image</label><input type="file" id="upload" name="upload" accept="image/*">
<p/>
<input type="submit" value="Go" >
</form>
Bare minimum form to work for you
You can add
<input type="hidden" name="MAX_FILE_SIZE" value="10485760"/>
before the file input field. This form element set the maximum file size of the file input field and it is measured in bytes. This MAX_FILE_SIZE is applied to the file inputs that come after it. Remember, this does not indicate the total size of all the input files. See the following example:
<input type="hidden" name="MAX_FILE_SIZE" value="10000"/>
<!--for these two consecutive input fields, maximum file size is 10000 bytes -->
<input type="file" name="userfile1"/>
<input type="file" name="userfile2"/>
<input type="hidden" name="MAX_FILE_SIZE" value="50000"/>
<!--for this input field, maximum file size is 50000 bytes -->
<input type="file" name="userfile3"/>
Save below as index.php and create a folder in the same directory called images. Remember to chmod the images folder to 777 once on the server.
<?php
if(isset($_GET['do']) && $_GET['do'] == 'upload2') {
// Start
$allowed_filetypes = array('.jpg','.jpeg','.png','.gif');
$max_filesize = 10485760;
$upload_path = 'images/';
$filename = $_FILES['userfile']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) {
// $query = "INSERT INTO uploads (name, description) VALUES ($filename, $description)";
// mysql_query($query);
echo 'Your file upload was successful!';
} else {
echo 'There was an error during the file upload. Please try again.';
}
// Finish
} elseif(isset($_GET['do']) && $_GET['do'] == 'upload1') {
echo '
<form action="index.php?do=upload2" method="post" enctype="multipart/form-data">
<input type="file" name="userfile"/>
<button name="upload" type="submit" value="Submit">
</form>
';
} else {
echo 'Link';
}
?>