A simple example of PHP image uploading (quick start)
-
2. admin_upfile.php
-
-
- Date_default_timezone_set ('prc ');
- // Upload $ upsize here to determine the size of the uploaded file
- $ Uppath = isset ($ _ REQUEST ["upPath"])? $ _ REQUEST ["upPath"]: "/attached/"; // file Upload path
- $ FormName = isset ($ _ REQUEST ["formName"])? $ _ REQUEST ["formName"]: "myform"; // upload the Name of the Form in the edit box of the previous page.
- $ EditName = isset ($ _ REQUEST ["editName"])? $ _ REQUEST ["editName"]: $ _ REQUEST ["editName"]; // The Name of the edit box on the upload page.
- // 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 );
- // If (is_dir ($ filename. "/". $ ctime )! = TRUE) mkdir ($ filename. "/". $ ctime, 0777 );
-
- $ F = $ _ FILES ['file1'];
-
- 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 ";
- // Echo $ f ['type'];
- 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;
- // $ New_file_name = md5 (date ("YmdHis"). '_'. rand (10000,999 99). '.'. $ file_ext;
-
- $ Dest = $ uppaths. $ filename. "/". date ("ymdhis"). "_". $ new_file_name; // Set the file name to the date plus the file name to avoid repeated Upload directories
- $ 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 );
- If ($ f ['size']> 0 ){
-
- Echo "scriptpolicw.opener.doc ument.". $ formName. ".". $ editName. ". value = '". $ dest1. "' script";
- Echo "script" alert ('image uploaded successfully'); window. close () script ";
- }
- ?>
-
3. admin_upload.php
-
-
- Picture upload_bbs.it-home.org
-
- $ Uppath = isset ($ _ REQUEST ["upPath"])? $ _ REQUEST ["upPath"]. "/": "/attached/"; // file Upload path
- $ FormName = isset ($ _ REQUEST ["formName"])? $ _ REQUEST ["formName"]: "myform"; // upload the Name of the Form in the edit box of the previous page.
- $ EditName = isset ($ _ REQUEST ["editName"])? $ _ REQUEST ["editName"]: $ _ REQUEST ["editName"]; // The Name of the edit box on the upload page.
- ?>
-
|