tailieunhanh - Beginning Ajax with PHP From Novice to Professional P5
Lưu ý lớp noshow, được thiết lập trong thẻ đầu của tài liệu của bạn. Lớp noshow là những gì sẽ làm cho khung nội tuyến của bạn có hiệu quả vô hình. Để thực sự quá trình tải lên, bạn đang sử dụng một chút của Ajax-kích hoạt JavaScript | CHAPTER 6 IMAGES 89 into. Note the noshow class which is set up within the head tag of your document. The noshow class is what will make your iframe effectively invisible. In order to actually process the upload you are using a bit of Ajax-enabled JavaScript. The JavaScript to perform the upload can be found within the file and is a function called uploadimg. This function is called when the submit button is clicked. function uploadimg theform Submit the form. For now this file contains only one function uploadimg which will simply be used to submit your form but as you build upon this example throughout the chapter it will become a more crucial element in building a full Ajax structure. Once the form submits the following PHP file loaded into the iframe will handle the actual file upload. Consider the PHP script in Listing 6-2. Listing 6-2. The PHP Code Required to Upload the Image php Allowed file MIME types. allowedtypes array image jpeg image pjpeg image png image gif Where we want to save the file to. savefolder images If we have a valid file if isset _FILES myfile Then we need to confirm it is of a file type we want. if in_array _FILES myfile type allowedtypes Then we can perform the copy. if _FILES myfile error 0 thefile savefolder . . _FILES myfile name if move_uploaded_file _FILES myfile tmp_name thefile echo There was an error uploading the file. else Signal the parent to load the image. 90 CHAPTER 6 IMAGES DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN http TR xhtml1 DTD html xmlns http 1999 xhtml head script type text javascript src script head body onload doneloading parent thefile img src thefile body html php In this PHP code you first create two variables that you will use to determine what type of file you want uploaded and where you want to put it. The allowedtypes array contains a listing of MIME types
đang nạp các trang xem trước