PHP entry level file picture upload code

Source: Internet
Author: User
Tags hash

$uploaddir = "../www.111cn.net/upload_img/";
$type = Array ("JPG", "gif", "BMP", "JPEG", "PNG");
$patch = "http://localhost/sl/upload_img/";
?>

The code is as follows Copy Code

<?php
Get file suffix name function
function Fileext ($filename)
{
Return substr (STRRCHR ($filename, '. '), 1);
}

Generate file Random name function
function Random ($length)
{
$hash = ' cr-';
$chars = ' abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz ';
$max = strlen ($chars)-1;
Mt_srand (Double) microtime () *1000000);
for ($i = 0; $i < $length; $i + +)
{
$hash. = $chars [Mt_rand (0, $max)];
}
return $hash;


$a =strtolower (fileext ($_files[' file ' [' name '])];
Determine the type of file
if (Strtolower (Fileext ($_files[' file ' [' name ']), $type))!in_array
{
$text =implode (",", $type);
echo "You can only upload the following types of files:", $text, "<br>";
}
Generate file name for target file
else{
$filename =explode (".", $_files[' file '] [' name ']);
Todo
{
$filename [0]=random (3);
$name =implode (".", $filename);
$name 1= $name. " MCNCC ";
$uploadfile = $uploaddir. $name;
}
while (File_exists ($uploadfile));
if (move_uploaded_file ($_files[' file '] [' tmp_name '], $uploadfile)) {
if (is_uploaded_file ($_files[' file '] [' tmp_name '])) {
if ($_files[' file '] [' size ']>0] {
Preview of output picture
echo <center> your file uploaded please see the preview of upload Picture: </center><br><center></ Center> ";
echo "<br><center><a href= ' example2_9.php ' > continue to upload </a></center>";
}
else{
echo "Upload failed! ";
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.