Php image uploading client and server implementation _ PHP Tutorial

Source: Internet
Author: User
Php client and server implementation for uploading images. Php image upload client and server implementation method this article mainly introduces php image upload client and server implementation method, involving php file operation skills, how to upload an image client and a server using php with an image suffix

This article mainly introduces the implementation of php image uploading client and server. it involves php file operation skills, and common methods such as image suffix verification and file rename. it has some reference value, for more information, see

This example describes how to upload images to the client and server in php. Share it with you for your reference. The details are as follows:

Front-end form code

?

1

2

3

4

Backend php code

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

// Upload $ upsize here to determine the size of the uploaded file

$ Uppath = "/attached/"; // file Upload path

// Convert the root directory path

If (strpos ($ uppath, "/") = 0)

{

$ I = 0;

$ Thpath = $ _ SERVER ["SCRIPT_NAME"];

$ Thpath = substr ($ thpath, 1, strlen ($ thpath ));

While (strripos ($ thpath ,"/")! = False)

{

$ Thpath = substr ($ thpath, strpos ($ thpath, "/") + 1, strlen ($ thpath ));

$ I = ++ $ I;

}

$ Pp = "";

For ($ j = 0; $ j <$ I; ++ $ j)

{

$ Pp. = "../";

}

$ Uppaths = $ pp. substr ($ uppath, 1, strlen ($ thpath ));

}

$ Filename = date ("y-m-d ");

If (is_dir ($ uppaths. $ filename )! = TRUE)

Mkdir ($ uppaths. $ filename, 0777 );

$ F = $ _ FILES ['Pic '];

If ($ f ["type"]! = "Image/gif" & $ f ["type"]! = "Image/pjpeg" & $ f ["type"]! = "Image/jpeg" & $ f ["type"]! = "Image/x-png ")

{

Echo "script" alert ('only images can be uploaded '); window. close () script ";

Return false;

}

// Obtain the file extension

$ Temp_arr = explode (".", $ f ["name"]);

$ File_ext = array_pop ($ temp_arr );

$ File_ext = trim ($ file_ext );

$ File_ext = strtolower ($ file_ext );

// New file name

$ New_file_name = md5 (date ("YmdHis"). '.'. $ file_ext;

Echo $ dest = $ uppaths. $ filename. "/". date ("ymdhis ")."_".

$ New_file_name; // Set the file name to the date plus the file name to avoid repeated Upload directories.

Echo $ dest1 = $ uppath. $ filename. "/". date ("ymdhis ")."_".

$ New_file_name; // Set the file name to the date plus the file name to avoid duplication.

$ R = move_uploaded_file ($ f ['tmp _ name'], $ dest );

?>

I hope this article will help you with php programming.

This article describes how to upload an image client and a server in php. it involves php file operations and image suffix verification...

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.