Php image uploading solution

Source: Internet
Author: User
Php uploads an image on the webpage. I want to preview it first. for example, if the uploaded image is displayed on the webpage, what should I do? echo & quot; & lt; imgsrc = '$ tmp_name' & gt; & quot; write like this? How should I write? how can I write a picture after the upload time? & nbsp; & lt ;? Phpif (is _ php uploads images
On the webpage, I want to preview it first. for example, if the picture I just uploaded is displayed on the webpage, what should I do? should I not echo ""; should I write it like this? How to write?

How to rewrite the code by naming the image with the upload time



If (is_uploaded_file ($ _ FILES ['upfile'] ['tmp _ name']) {

$ Upfile = $ _ FILES ["upfile"];

$ Name = $ upfile ["name"];
$ Type = $ upfile ["type"];
$ Size = $ upfile ["size"];
$ Tmp_name = $ upfile ["tmp_name"];
$ Error = $ upfile ["error"];


Switch ($ type ){
Case 'image/pjpeg ': $ OK = 1;
Break;
Case 'image/jpeg ': $ OK = 1;
Break;
Case 'image/GIF': $ OK = 1;
Break;
Case 'image/png ': $ OK = 1;
Break;
}

If ($ OK & $ error = '0 '){
Move_uploaded_file ($ tmp_name, 'up/'. $ name );
Echo "uploaded successfully ";
Echo "$ name
";
Echo "$ type
";
Echo "$ size
";
Echo "$ tmp_name
";


}
}


?>




------ Solution --------------------
I seem to remember which post you asked this question? I wanted to answer your question this afternoon. Why did you send it here?
What time does your time mean? Timestamp?

Modify here
// Move_uploaded_file ($ tmp_name, 'up/'. $ name );
// Get the file extension
$ Oldname = $ upfile ['name']; // note the inclusion path.
$ Fileexpand = pathinfo ($ oldname, PATHINFO_EXTENSION );
$ Filename = strtotime (); // Time stamp
// $ Filename = date ('ymmdgis '); // Beijing time
Move_uploaded_file ($ tmp_name, 'up/'. $ filename. $ fileexpand );

------ Solution --------------------
Move_uploaded_file ($ tmp_name, 'up/'. $ filename. $ fileexpand );

Here the error is changed
Move_uploaded_file ($ tmp_name, 'up/'. $ filename.'. '. $ fileexpand );

The code above is what you want
How to rewrite the code by naming the image with the upload time

There is another question: Preview the image.
You can use JavaScript to control a hidden div to read the image and assign the file name to js after uploading...
Maybe you cannot understand ....

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.