Updating wrong image using PHP MySQL - php

I am trying to allow admin to update photos of advertisements. I've managed to get the update part working, but it keeps updating the wrong advertisement (the first one in the database). I think it might not be registering the ID of the one I want to update when it is submitting to the database but I can't see what I have done wrong. I've used this code before for a profile picture update, but i'm guessing it's the session that is making it do this?
Here is my adupload.php code
<?php
$id=$_POST['id'];
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "<b><center>The file uploaded was not an image!<br><center>Go back here!";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "<b><center>Sorry, this image already exists! <br><center>Go back here!";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 50000000) {
echo "<b><center>Sorry, your image is too large.<br><center>Go back here!";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType
!= "jpeg"
&& $imageFileType != "gif" ) {
echo "<b><center>Sorry, only JPG, JPEG, PNG & GIF files are allowed.<br>
<center>Go back here!";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "<b><center>Sorry your picture was not uploaded.<br><center>Go back here!";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
$target_file)) {
echo "<center>Your profile picture ". basename(
$_FILES["fileToUpload"]["name"]). " has been uploaded! <br><center>Go back to the admin area";
$sql = "UPDATE advertisement SET imageName='$target_file' WHERE
id=$id";
mysqli_query($mysqli_conn, $sql);
} else {
print "<b><center>An error occurred when uploading your picture<br>
<center>Go back here!";
}
}
?>
Here is a snippet of update_ad.php
$id = $_GET['id'] ; //Get the primary key passed
$query = "SELECT * FROM advertisement WHERE id = '$id' ";
//if error in query, display
$result = mysqli_query($mysqli_conn, $query) or exit ("Error in query:
$query. ".mysqli_error());
//see if any rows were returned
if (mysqli_num_rows($result) > 0) { // yes then display Form
$row = mysqli_fetch_assoc($result); //then fetch the row
?>
<table border= "3" style="width:100%;margin:auto">
<form action = 'update_ad_action.php' method="POST">
<tr><td>ID:</td><td><input readonly="yes" name="id" type="text" value=<?
php echo $id; ?> size="3" ></td></tr>
<tr><td>Title:</td><td><input type="text" name="title" value=<?php echo
$row["title"] ?> ></td></tr>
<tr><td>Description:</td><td><input type="text" name="description" value=
<?php echo $row["description"] ?> ></td></tr>
<tr><td>From-date:</td><td><input type="text" name="from_date" value=<?
php echo $row["from_date"] ?> ></td></tr>
<tr><td>To-date:</td><td><input type="text" name="to_date" value=<?php
echo $row["to_date"] ?> ></td></tr>
<tr><td>Pets:</td><td><select name="pets" id="pets">
<option value="0">Yes</option>
<option value="1">No</option></td></tr>
<tr><td>Location:</td><td><input type="text" name="location" value=<?php
echo $row["location"] ?> ></td></tr>
<tr><td>Picture</td><td><img src=" <?php echo $row['imageName'] ?>"
alt="No picture uploaded" width="200" height ="200" ></td></tr>
<tr><th colspan="2"><center><input class="button button-primary"
type="Submit" value="Submit"/>&nbsp<input class="button button-primary"
type="reset" value="Clear"/></center></th></tr>
</form>
</table>
<br>
<table border= "3" style="width:100%;margin:auto">
<form action="adupload.php" method="post" enctype="multipart/form-data">
<tr><td>Want to change your picture?</td><td>
<input type="hidden" name="id" value="<?php echo $_SESSION['id']; ?>">
<input type="file" name="fileToUpload" id="fileToUpload" required></td>
</tr>
<tr><th colspan="2"><center><input class="button button-primary"
type="submit" value="Upload Image" name="submit"></center></th></tr>
</form></table>
update_ad_action.php
<?php require 'config/init.php' ;
$id = $_POST['id']; //get id passed
$errorString = ""; //string to collect errors if found
$title = trim($_POST["title"]); //trim white spaces
if (empty($title)) {
$errorString = $errorString."<br><center>Please enter a title.
</center>"; //if empty, error added to error string
//remove any slashes that are automatically added, strip tags and
disable html tags from having any affect
$title = htmlentities(strip_tags($title));
}
$description = trim($_POST["description"]);
if (empty($description)) {
$errorString = $errorString."<br><center>Please enter a description.<
</center>"; //if empty, error added to error string
//remove any slashes that are automatically added, strip tags and
disable html tags from having any affect
$title = htmlentities(strip_tags($description));
}
$from_date = trim($_POST["from_date"]);
if (empty($from_date)) {
$errorString = $errorString."<br><center>Please enter a from date.
</center>"; //if empty, error added to error string
//remove any slashes that are automatically added, strip tags and disable
html tags from having any affect
$title = htmlentities(strip_tags($from_date));
}
$to_date = trim($_POST["to_date"]);
if (empty($to_date)) {
$errorString = $errorString."<br><center>Please enter a to date.
</center>"; //if empty, error added to error string
//remove any slashes that are automatically added, strip tags and disable
html tags from having any affect
$title = htmlentities(strip_tags($to_date));
}
$location = trim($_POST["location"]);
if (empty($location)) {
$errorString = $errorString."<br><center>Please enter a location</center>
"; //if empty, error added to error string
//remove any slashes that are automatically added, strip tags and disable
html tags from having any affect
$title = htmlentities(strip_tags($location));
}
// check if there were any errors
if (empty($errorString)) {//No errors, update the data
//query to update data
$query = "UPDATE user SET title = '$title', description = '$description',
from_date = '$from_date', to_date = '$to_date', location = '$location'
WHERE id = '$id'";
$result = mysqli_query($mysqli_conn, $query);
//if there was a problem - get the error message and go back
if (mysqli_affected_rows($mysqli_conn) < 0) {
echo "There were errors :<br>" . mysql_error();
echo $query;
exit ;
} else { //locate back to profile if updated
header("Location: admin.php");
}
} else {//There were errors
print '<b><center>There were errors<br>' . $errorString . "<center>Go back here!";
}
?>

The ID in your $_SESSION['id'] is likely to be wrong and thus you are sending always the same ID.
If you want to get the ID passed by URL (?id=1337), use <?php echo $_GET['id']; ?> in the form instead of $_SESSION.

where are you setting $_SESSION['id'] = $id? - if you are not setting that then this input will have no value.
<input type="hidden" name="id" value="<?php echo $_SESSION['id']; ?>">
you could change it to:
<input type="hidden" name="id" value="<?php echo $id; ?>">
also I am not loving the space in the name you posted
imageName='uploads/2015-10-04 19.59.41.jpg'
should really be with a hyphen or an underscore.:
imageName='uploads/2015-10-04_19.59.41.jpg'

you need ' ' around the variable in your update query in your adupload.php code:
$sql = "UPDATE advertisement SET imageName='$target_file' WHERE
id=$id";
should be
$sql = "UPDATE advertisement SET imageName='$target_file' WHERE
id='$id'";

Related

PHP / MySQL: Image successfully save to database but failed to display at web page

I have a very weird problem in my system. I already create a system to upload the image to the database and display it. The problem is, the image is successfully uploaded but, it will return the message "Failed to upload!". Then, the picture that had been uploaded does not display. Below is my code:
<body>
<div class="wrapperDiv">
<form action="" method="post" id="form" enctype="multipart/form-data">
Upload image :
<input type="file" name="uploadFile" value="" />
<input type="submit" name="submitBtn" value="Upload" />
</form>
<?php
$last_insert_id = null;
include('db2.php');
if(isset($_POST['submitBtn']) && !empty($_POST['submitBtn'])) {
if(isset($_FILES['uploadFile']['name']) && !empty($_FILES['uploadFile']['name'])) {
//Allowed file type
$allowed_extensions = array("jpg","jpeg","png","gif");
//File extension
$ext = strtolower(pathinfo($_FILES['uploadFile']['name'], PATHINFO_EXTENSION));
//Check extension
if(in_array($ext, $allowed_extensions)) {
//Convert image to base64
$encoded_image = base64_encode(file_get_contents($_FILES['uploadFile']['tmp_name']));
$encoded_image = $encoded_image;
$query = "INSERT INTO tbl_images SET encoded_image = '".$encoded_image."'";
$sql = $conn->prepare($query);
$sql -> execute();
//$results = $sql -> fetchAll(PDO::FETCH_OBJ);
echo "File name : " . $_FILES['uploadFile']['name'];
echo "<br>";
if($sql->rowCount() > 1 ) {
echo "Status : Uploaded";
$last_insert_id = $conn-> lastInsertId();
} else {
echo "Status : Failed to upload!";
}
} else {
echo "File not allowed";
}
}
if($last_insert_id) {
$query = "SELECT encoded_image FROM tbl_images WHERE id= ". $last_insert_id;
$sql = $conn->prepare($query);
$sql -> execute();
if($sql->rowCount($sql) == 1 ) {
//$row = mysqli_fetch_object($result);
while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
echo "<br><br>";
echo '<img src="'.$row->encoded_image.'" width="250">';
}
}
}
}
?>
</div>
</body>
Can someone help me? Thanks!
you doing some thing wrong first you encoded the image when store in database so you must decode it again, and the src in tag get a url not image content just echo the content like this:
header('Content-type: image/jpeg');
echo base64_decode($row->encoded_image);
or
<img src="data:image/png;base64,'.$row->encoded_image.'" width="250">
but at all, store images in database is not a good option, your database become too heavy and can't respond fast and get too memory you can just store the image name in database and move the file form special place in your server the you can show like this.
echo '<img src="specialRoot/'.$row->image_name.'" width="250">';
Store images in folder..
I have created uploads folder in root, you can create folder at anywhere and write your path while fetching the image..
<body>
<div class="wrapperDiv">
<form action="" method="post" id="form" enctype="multipart/form-data">
Upload image :
<input type="file" name="uploadFile" value="" />
<input type="submit" name="submitBtn" value="Upload" />
</form>
<?php
$last_insert_id = null;
include('db2.php');
if(isset($_POST['submitBtn']) && !empty($_POST['submitBtn'])) {
if(isset($_FILES['uploadFile']['name']) && !empty($_FILES['uploadFile']['name'])) {
//Allowed file type
$allowed_extensions = array("jpg","jpeg","png","gif");
$name = $_FILES['uploadFile']['name'];
$target_dir = "uploads/"; //give path of your folder where images are stored.
$target_file = $target_dir . basename($_FILES["uploadFile"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
//Check extension
if( in_array($imageFileType,$allowed_extensions) ){
//Convert image to base64
$image_base64 = base64_encode(file_get_contents($_FILES['uploadFile']['tmp_name']) );
$encoded_image = 'data:image/'.$imageFileType.';base64,'.$image_base64;
//$encoded_image = base64_encode($_FILES['uploadFile']['tmp_name']);
//$encoded_image = $encoded_image;
$query = "INSERT INTO tbl_images SET encoded_image = '".$encoded_image."'";
$sql = $conn->prepare($query);
$result = $sql -> execute();
move_uploaded_file($_FILES['uploadFile']['tmp_name'],$target_dir.$name);
echo "File name : " . $_FILES['uploadFile']['name'];
echo "<br>";
if($result == 1) {
echo "Status : Uploaded";
$last_insert_id = $conn->insert_id;
} else {
echo "Status : Failed to upload!";
}
} else {
echo "File not allowed";
}
}
if($last_insert_id) {
$query = "SELECT encoded_image FROM tbl_images WHERE id= ". $last_insert_id;
$result = $conn->query($query);
while($row = $result->fetch_assoc()){
echo '<img src="'.$row['encoded_image'].'" width="250">';
}
}
}
?>
</div>
</body>

Why does the submit button just reload my page instead of sending the information?

When I press the submit button the page reloads but doesn't send me to the "upload.inc.php" file. After clicking the submit button I just arrive at the index.php file without anything happend.
I copied the code and tried the html part in another file and there it worked. Therefore the mistake has to be somewhere in the rest of the index.php file. I added already echo's in the beginning of the "upload.inc.php" file and it didn't change a thing. Thus the error is somewhere in the index.php file but I don't find it. I appriciate your help! I searched for 4-5 hours and didn't find it.. .
Index.php (html part)
<form action="includes/upload.inc.php" method='post' enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='hidden' name='userId' value="<?php echo $id; ?>" >
<button type='submit' name='submit'>UPLOAD</button>
</form>
Index.php (full file)
<?php
require "header.php";
require "includes/dbh.inc.php";
?>
<main>
<?php
if (isset($_GET['login'])) {
//Login Bereich der Hilfe suchenden
if ($_GET['login'] == "successHelpSeeker") {
echo "<p> Hello help seeker. </p>";
}
//Login Bereich der Helfenden
elseif ($_GET['login'] == "successHelper") {
echo "<p> Hello Helper.</p>";
}
//Login Bereich für beide gleich
//Profilbild
$id = $_SESSION['userId'];
$sqlImg = "SELECT * FROM profileimg WHERE userid='$id'";
$resultImg = mysqli_query($conn, $sqlImg);
$rowImg = mysqli_fetch_assoc($resultImg);
echo "<div>";
//existiert schon ein Profilbild? bei 0 ja bei 1 nein
if ($rowImg['status'] == 0) {
echo "<img src='uploads/profile".$id.".jpg'>";
} else{
echo "<img src='uploads/profiledefault.jpg'>";
}
echo "<p>".$row['userid']."</p>";
echo "</div>";
//enctype specifies how the form data should be encoded --> ?>
<form action="includes/upload.inc.php" method='enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='hidden' name='userId' value="<?php echo $id; ?>" >
<button type='submit' name='submit'>UPLOAD</button>
</form>
<?php
}
if(isset($_SESSION['userId'])){
echo '<p>You are logged in!!</p>';
}
else{
echo '<p>You are logged out!</p>';
}
?>
</main>
normally it should send the choosen file to the upload.inc.php file but it just reloads the page without sending the information.
Thanks a lot for your help!
upload.inc.php :
<?php
session_start();
require 'dbh.inc.php';
$id = $_POST['userId'];
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fielType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) {
if ($fileSize < 10000000) {
$fileNameNew = "profile".$id.".".$fileActualExt;
$fileDestination = '../uploads/'.$fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$sql = "UPDATE profilimg SET status=0 WHERE userid= '$id';";
$result = mysqli_query($conn, $sql);
header("Location: ../index.php?uploadsuccess");
}
} else {
echo "Your file is too big. Please upload a file which isn't bigger than 10 mb.";
}
} else {
echo "There was an error uploading your file.";
}
} else {
echo "Please upload only jpg, jpeg, png or pdf files.";
}
The crazy thing is, I changed the "action" to a new file with barely something in it. Still the submit button doesn't send me to the new file and just reloads the page. Could it be a problem which has to do with the sessions I'm working with? :O
Look in your index.php page method='enctype='mltipart/form-data'
<form action="includes/upload.inc.php" method='enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='hidden' name='userId' value="<?php echo $id; ?>" >
<button type='submit' name='submit'>UPLOAD</button>
</form>
<?php
}

Does an update have to be different to an insert when uploading a file?

I'm having a problem with the update section of a CRUD I'm making. The create works fine, and I'm using very similar code for the update but there's something going wrong and it seems to be a problem with the file upload.
I have a page that displays all the rows from the database. There's a link next to each row that says edit and when that's clicked on, it goes to a page that displays the row from the Db in a form. The information can then be changed and there's a submit button that when clicked makes the action of the form run, which is a php file that has this:
<?php
include ('includes/DbCon.php');
if (isset($_POST['ud_id']))$id = $_POST['ud_id'];
$query = "SELECT * FROM news WHERE id = '$id'";
$result = $mysqli->query ($query);
if(mysqli_num_rows($result)>=1)
{
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
$headline = $row['headline'];
$body = $row['body'];
$image = $row['image'];
}
else{
$mysqli->error;
}
//Set directory etc for image upload
$target_dir = "images/photo/";
$target_file = $target_dir . basename($_FILES["ud_image"]["name"]);
if (move_uploaded_file($_FILES["ud_image"]["tmp_name"], $target_file)or die($mysqli->error))
{
echo '<script type="text/javascript">';
echo 'alert("News Items Saved")';
echo '</script>';
} else {
echo "Sorry, there was an error with your file.";
}
There's more to it but it doesn't get past this, so I need help figuring out what's wrong with it. I've used var_dump and also printed the variables to see what's getting passed and everything is fine until it get's to the $target_file. When I print that variable I get 'image/photo' but I suspect it should be the full file name as well as the target path.
It's set the same way as the insert code, so I don't know what's wrong with it.
As requested, here's the form:
<form action="update.php" method="post" class="newNews">
<input type="hidden" name="ud_id" value="<?=$id;?>">
<label for="title">Title</label><br />
<input type="text" name="ud_headline" value="<?=$headline;?>"/>
<label for="text">Body</label><br />
<textarea name="ud_body" rows="5" cols="21" value="" class="editBody"><?=$body;?></textarea>
<p>Current Photo</p>
<img src="images/photo/<?=$image?>" alt=" " width="auto" height="auto"><br />
<input type="file" name="ud_image" class="newsImage" ><br />
<input type="submit" name="submit" value="Update news item" class='addNew' />
</form>
It appears to be a problem with your move_uploaded_file() function. From the online manual:
http://php.net/manual/en/function.move-uploaded-file.php
Try this code:
<?php
...
if ($_FILES["ud_image"]["error"] == UPLOAD_ERR_OK)
{
$tmp_name = $_FILES["ud_image"]["tmp_name"];
$name = $_FILES["ud_image"]["name"];
if (move_uploaded_file($tmp_name, "$target_dir$name"))
{
echo '<script type="text/javascript">';
echo 'alert("News Items Saved")';
echo '</script>';
}
else
{
echo "Sorry, there was an error with your file.";
}
}
else
{
echo "Sorry, there was an error with your file.";
}

Issue with updating image info on MYSQL database using PHP

I'm having problem with my code. I can't update my image.
Here is my full code:
index.php
//this link will post my data to next page
update
updatepage.php
//this page will get all data that want to update...
<?php
include("config.php");
$name=$_GET['code'];
$sql1 = "select * from imagename where name='$name'";
$result = mysql_query($sql1) or die(mysql_error());
$row=mysql_fetch_array($result);?>
<form name="form1" method="post" action="processupdatepage.php" class="formposition" enctype="multipart/form-data" >
<table>
<tr><td>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" /></td></tr>
<tr><td width="98">Image</td><td width="288">
//This is where I have problem, I can't get my image value but other data value work very well.....
<input type="file" name="image" value="<?php echo $row['image'];?>" /></td></tr><br/>
<tr><td>nane</td><td><input type="text" name="name" value="<?php echo $row['name']; ?>"/></td></tr><br/>
<tr><td></td> <td colspan="2">
<input type="submit" name="submit" value="Save" /> </td></tr>
</table>
</form>
OK. Now this my process file:
processupdatepage.php
<?php
include("config.php");
$id=$_POST['id'];
$image=$_FILES['image']['name'];
$name=$_POST['name'];
$target = "images/";
$target = $target . basename( $_FILES['image']['name']);
$query = "UPDATE imagename SET name='$name', image='$image' WHERE id='$id'";
$bb = mysql_query($query) or die(mysql_error());
if($bb)
{
//Writes the photo to the server
if(move_uploaded_file($_FILES['image']['tmp_name'], $target))
{
$sql001="UPDATE imagename SET image='$image' WHERE image='$image'";
mysql_query($sql001);
} else { }
header("Location:index.php");
}
else
{
echo "Could not be updated";
}
?>
I can update BUT must select image. If I'm not selecting an image, my image field in database will be empty BUT other data updates are OK...
The value of an <input type="file"> cannot be programatically changed. Only by triggering its default behaviour that pops up the select file dialogue.
What I see from you example code is that you want to associate the value to the file form control element straight as it was retrieved from the database. So why saving the same back. Still, if you want to do this, you can use a hidden element with the value, that will be saved. But if you don't want the user to change it, just don't render it into the form and leave it out from your update query so it will remain unchanged.
Also, you could add some logic when you process the post and leave the field 'image' out of your update query if no file was selected.
I think the problem is here:
<input type="file" name="image" value="<?php echo $row['image'];?>" />
You can upload the image by clicking the browse button. so what do you trying to do like that?
If you want to show the image already uploaded you can use :
$img_path = 'get image path from database entry';
<img src= "<?php echo $img_path; ?>"/>
Here is full code to upload an Image, this is tested and works but you need to have a directory called 'upload' (this code does not create the folder).
It is advisable to only store image path on database.
<?php
if(isset($_POST['submit'])){
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 200000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
if (file_exists("upload/" . $_FILES["file"]["name"])){
echo $_FILES["file"]["name"] . " already exists. ";
}
else{
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
// HERE YOU CAN WRITE YOU INSERT INTO MYSQL CODE
//SOMETHING LIKE THIS:
$path = 'assets/article_images/'.$article_id.'/'.$_FILES["image_file"]["name"];
$statement1 = "INSERT INTO image_article (article_id, image_path) values ('$article_id', '$path') ";
$query_result = mysql_query($statement1) or die($statement1."mysql error<br/><br/>".mysql_error());
if($query_result==1){
echo 'Image uploaded';
}
}
}
}
else
{
echo "Invalid file";
}
}
?>
<html>
<body>
<form action="index.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

php .flv file uploading issue

well I can upload image, mp3, mp4, .doc file etc with the following form. But it's doesn't upload .flv file. Anyone can tell me what is the problem in my code or how can i upload .flv..
<?php
$mysql_connect = mysql_connect("localhost", "root" );
mysql_select_db("vedio");
ini_set('upload_max_filesize','1000M');
if(isset($_POST['action']) == "upload")
{
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$size = $_FILES['file']['size'];
$type = $_FILES['file']['type'];
$name = str_replace(" ", "", $name);
$sql = mysql_query("INSERT INTO content VALUES('',
'$name', '$tmp_name', '$size' )");
if($sql)
{
echo "successfully uploaded";
}
else
{
echo "Something is wrong to upload";
}
$upload = "vedio/";
move_uploaded_file($_FILES['file']['tmp_name'], $upload . $name);
echo "<br/>";
echo $name;
echo "<br/>";
echo $tmp_name;
echo "<br/>";
echo $size;
echo "<br/>";
echo $type;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="file" name="file" /></td>
<td><input type="submit" value="upload" name="action" /></td>
</tr>
</table>
</form>
Many Thanks.
Shibbir
My guess is your flv is probably just too big..
upload_max_filesize alone is not enough to set, you also need to set post_max_size otherwise your POST request will be empty and your upload will fail (it'll essentially look like a non-post request).
This line doesn't make sense
if(isset($_POST['action']) == "upload")
you are calling isset() which is going to return true or false depending upon if that variable is given a value and then you compare that true or false with the string "upload" which obviously would never be equal. You either need to check if the variable is set or check if the value is equal to "upload".
if(isset($_POST['action']) && $_POST['action'] == "upload")
Should also check for file upload errors. Something like:
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else {
echo "No file upload errors";
}

Categories