Saturday, August 4, 2018

how to create upload file in php

Configure The "php.ini" File

First, ensure that PHP is configured to allow file uploads.
In your "php.ini" file, search for the file_uploads directive, and set it to On:
file_uploads = On

Create The HTML Form

Next, create an HTML form that allow users to choose the image file they want to upload:
<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>
Some rules to follow for the HTML form above:
  • Make sure that the form uses method="post"
  • The form also needs the following attribute: enctype="multipart/form-data". It specifies which content-type to use when submitting the form
Without the requirements above, the file upload will not work.
Other things to notice:
  • The type="file" attribute of the <input> tag shows the input field as a file-select control, with a "Browse" button next to the input control
The form above sends data to a file called "upload.php", which we will create next.


Create The Upload File PHP Script

The "upload.php" file contains the code for uploading a file:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake imageif(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
?>
PHP script explained:
  • $target_dir = "uploads/" - specifies the directory where the file is going to be placed
  • $target_file specifies the path of the file to be uploaded
  • $uploadOk=1 is not used yet (will be used later)
  • $imageFileType holds the file extension of the file (in lower case)
  • Next, check if the image file is an actual image or a fake image
Note: You will need to create a new directory called "uploads" in the directory where "upload.php" file resides. The uploaded files will be saved there.

Check if File Already Exists

Now we can add some restrictions.
First, we will check if the file already exists in the "uploads" folder. If it does, an error message is displayed, and $uploadOk is set to 0:
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}

Limit File Size

The file input field in our HTML form above is named "fileToUpload".
Now, we want to check the size of the file. If the file is larger than 500KB, an error message is displayed, and $uploadOk is set to 0:
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}

Limit File Type

The code below only allows users to upload JPG, JPEG, PNG, and GIF files. All other file types gives an error message before setting $uploadOk to 0:
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}

Complete Upload File PHP Script

The complete "upload.php" file now looks like this:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake imageif(isset($_POST["submit"])) {
    $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
    if($check !== false) {
        echo "File is an image - " . $check["mime"] . ".";
        $uploadOk = 1;
    } else {
        echo "File is not an image.";
        $uploadOk = 0;
    }
}
// Check if file already existsif (file_exists($target_file)) {
    echo "Sorry, file already exists.";
    $uploadOk = 0;
}
// Check file sizeif ($_FILES["fileToUpload"]["size"] > 500000) {
    echo "Sorry, your file is too large.";
    $uploadOk = 0;
}
// Allow certain file formatsif($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an errorif ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload fileelse {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
?>

Monday, July 9, 2018

LUKA MODRIC ON CRISTIANO RONALDO MOVE TO JUVENTUS.


Luka Modric gave an interesting response when asked about Cristiano Ronaldo leaving Real Madrid for Juventus.
The Serie A giants have agreed personal terms with Ronaldo, and he is set to leave Real Madrid in a deal worth £88million to start a new life in Italy.
The Old Lady, who are currently locked in talks with Los Blancos, had hoped to get the deal over the line before the weekend so that they could unveil their marquee signing at the Juventus Stadium in Turin on Saturday.
But they failed to do so, and Modric, who netted a penalty in Croatia's shoot-out win over World Cup hosts Russia in the quarter-finals of the competition on Saturday, isn't convinced the deal will go through.
Russia-v-Croatia-Quarter-Final-2018-FIFA-World-Cup-Russia.jpg
Luka Modric spoke out about Cristiano Ronaldo after Croatia's win(Image: Shaun Botterill)
Soccer-Football-World-Cup-Portugal-Departure.jpg
The Portuguese is linked with an £88million move to Juventus(Image: REUTERS)
"Let's see what happens," the Croatian told the press shortly after his nation's historic victory. "I don't think he's going to leave, and I'd like him to stay because he's the best player in the world.
"I think he's going to stay; that's my opinion. I can't imagine him at any other club."
Juventus fans are getting a little ahead of themselves in regards to Ronaldo signing.
source(https://www.mirror.co.uk)

Sports #on transfers

Jurgen Klopp has been urged to sign South
Korea goalkeeper Cho Hyun-woo as a
replacement for Loris Karius by one of his
close advisors.
Liverpool are reportedly in the market for a
new first-choice goalkeeper and have been
heavily linked with Atletico Madrid’s Jan
Oblak and Roma’s Alisson. But Jorn
Andersen has revealed that he told Klopp via
a text message in December that he should
closely monitor Cho’s progress in South
Korea.
Cho was expected to be South Korea’s
back-up option at the World Cup this
summer but the 26-year-old ended up being
one of the tournament’s surprise stars as he
impressed in all three group games against
Germany, Mexico and Sweden.
Andersen, meanwhile, is a close friend of
Klopp following their time together as
players at Eintracht Frankfurt and still
remains in contact with the Liverpool
manager.
When he was in charge at Mainz, Klopp
signed Blaise Nkufo and Sven Christ after
personally asking Andersen for his
recommendations.
‘He has listened to me before, so it would be
nice if he does it again,’ Andersen said in
an interview with Dagbladet. ‘I am convinced
that Cho Hyun-woo will be a good choice for
Liverpool.
‘I do not think Klopp will continue with
Karius, I think Liverpool will pick up a new
goalkeeper after the World Cup.
‘Not only because of what happened in the
Champions League final, simply because he
must have someone who is better than he
has. ‘And I’m sitting with the feeling that
Cho can end up in Liverpool. He was very
good for South Korea in the three matches
he played at the World Cup.’

Sports #transfer speculations

Fernando Hierro has stepped down as Spain's interim head coach following their last-16 exit to World Cup hosts Russia on penalties. (Source: SkySports) https://t.co/l8i9Hlbgt5

Manchester United are confident of beating Barcelona to the signature of Chelsea's £60m-rated Willian now Brazil are out of the World Cup. (Source: Sun Sport) https://t.co/eJ2Hz2851P

Manchester United are set to test PSV's resolve to hold onto Mexico winger Hirving Lozano with a £35m bid. (Source: Tuttomercatoweb) https://t.co/Yw0a1VPsC3

West Ham United have made a £17.5m bid for Borussia Dortmund forward Andriy Yarmolenko. (Source: SkySports) https://t.co/fhc6rQigWj

Real Madrid are lining up a swoop for Lazio midfielder Sergej Milinković-Savić in a deal which could cost the European champions in excess of £137m. (Source: Corriere dello Sport) https://t.co/4mirhJCohZ

Paul Pogba is ready to leave Manchester United this summer, with Barcelona his preferred destination. (Source: Don Balon) https://t.co/PfhxxNeMqz

Jack Wilshere has started a medical at West Ham as the Hammers look to sign the 26-year-old midfielder on a three-year contract and a package worth £5m. (Source: Times) https://t.co/n19EJM7dh1

Wilfried Zaha has turned down a £120k-a-week deal at Crystal Palace amid interest from Spurs, Everton and Dortmund. (Source: Sun Sport) https://t.co/OV01e1ukab

Valencia have agreed a €17m deal for Kevin Gameiro, but it will not be announced until Nikola Kalinić is certain to replace him at Atlético Madrid. (Source: MARCA) https://t.co/ZbZMh4hQYu

Paris St-Germain are willing to pay more than £100m for Chelsea and France midfielder N'Golo Kanté. (Source: Goal) https://t.co/xRjvnd5tV6

Tottenham have emerged as frontrunners in the race to sign Jack Grealish, with the north London club hoping to land the Aston Villa midfielder for just £12m. (Source: Evening Standard) https://t.co/0a0fXCwIC1

DONE DEAL: Paulinho has joined Guangzhou Evergrande on a one-year loan deal. https://t.co/hQoxxJp1PR

Barcelona secure a profit on the €40m they paid for Paulinho 12 months ago:
https://t.co/3YN6WtRVps https://t.co/xvrKQfy4Y0

DEAL DONE: Chinese club Guangzhou Evergrande have announced that Paulinho has joined the club from Barcelona in a one-year loan deal with the option to buy.

Such an odd transfer. 🤔📝 https://t.co/92naoxQK4E

Friday, July 6, 2018

TODAY'S TOP HITS


Today's top hit songs
1.
Girls Like You (feat. Cardi B)
3:55
2.
Bed (feat. Ariana Grande)
3:09
3.
Ocean (feat. Khalid)
3:36
4.
Don’t Matter To Me
4:05
5.
Jackie Chan
3:35
6.
Taste (feat. Offset)
3:52
7.
Youngblood
3:23
8.
Lucid Dreams
3:59
9.
APESHIT
4:24
10.
Nonstop
3:58
11.
Solo (feat. Demi Lovato)
3:42
12.
Start Again (feat. Logic)
2:45
13.
I Like It
4:13
14.
Rise
3:14
15.
Boo'd Up
4:16
16.
Back To You - From 13 Reasons Why – Season 2 Soundtrack
3:27
17.
In My Feelings
3:37
18.
Better Now
3:51
19.
I'm a Mess
3:15
20.
Born To Be Yours
3:13
21.
Better Not (feat. Wafia)
3:42
22.
Enemies
3:14
23.
ocean eyes
3:20
24.
Like To Be You feat. Julia Michaels
2:39
25.
no tears left to cry
3:25
26.
High Hopes
3:10
27.
Connection
2:28
28.
Body
2:43
29.
If You're Over Me
3:09
30.
Emotionless

5:02

Contact Us

Name

Email *

Message *