Zaloguj | Zarejestruj | FAQ
Anonymous

how to uplaod image in php script?

+ Odpowiedz

Posty: 6 Strona 1 z 1


how to uplaod image in php script?

przez freelancerboy » N kwi 05, 2015 4:58 pm

I am new in php and learning regularly.
how to upload image at php script? i want to upload image randomly.
anybody can explain me easily?
<input type="file" name="upload" />
Avatar użytkownika

freelancerboy

  • Posty: 3
  • Dołączył(a): Śr kwi 01, 2015 3:33 pm
  • Lokalizacja: Bangladesh

Re: how to uplaod image in php script?

przez XainPro » Śr kwi 15, 2015 5:50 pm

<?php
$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 "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 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;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
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.";
}
}
?>
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm

Re: how to uplaod image in php script?

przez Chikwado » Pt kwi 17, 2015 10:05 am

This code does not work for me, I have this code here: http://chiquado.site90.net/upload It return error, was it from my hosting server, or what?
Avatar użytkownika

Chikwado

  • Posty: 94
  • Dołączył(a): Pn lip 29, 2013 11:36 pm
  • Lokalizacja: Nigeria
--
Focus On Advance Science And Programming.

Re: how to uplaod image in php script?

przez XainPro » Pt kwi 17, 2015 1:53 pm

it's not showing the error what is the error exactly ?
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm

Re: how to uplaod image in php script?

przez Chikwado » N kwi 19, 2015 4:14 pm

@Xainpro help me check this script once more, This script always return error http://chiquado.site90.net/upload
Avatar użytkownika

Chikwado

  • Posty: 94
  • Dołączył(a): Pn lip 29, 2013 11:36 pm
  • Lokalizacja: Nigeria
--
Focus On Advance Science And Programming.

Re: how to uplaod image in php script?

przez XainPro » So maja 02, 2015 3:33 pm

the link is broken
Avatar użytkownika

XainPro

  • Posty: 3933
  • Dołączył(a): Pt lut 17, 2012 8:10 pm


+ Odpowiedz

Strona 1 z 1

cron