Home >Backend Development >PHP Tutorial >php swfupload image upload sample code

php swfupload image upload sample code

怪我咯
怪我咯Original
2017-07-12 09:29:031181browse

SWFUpload is a file upload plug-in that combines flash and js. Its function is very powerful.

Features of SWFUpload

1. Use flash to upload , the page does not refresh, and the style of the Flash button can be customized;

2. You can limit the files to be uploaded on the browser side;

3. Allow multiple files to be uploaded at one time , but there will be an uploadqueue. The files in the queue are uploaded one by one. When the server receives the file, it is the same as the ordinary form upload file;

4. Provides a wealth of The event interface is for developers to use;

SWFUpload file upload process:

1. Introduce the corresponding js file

2. Instantiate SWFUpload Object, pass in a configuration parameter object to configure various aspects.

3. Click the Flash button provided by SWFUpload, and the file selection window will pop up to select the file to be uploaded;

4. After the file selection is completed, the files that meet the requirements will be added to the upload queue;

5. Call the startUpload method to start uploading files in the queue;

6. Corresponding events will be triggered during the file upload process. Developers use these events to update the UI, handle errors, and issue prompts. Wait;

The following is the sample code for php swfupload image upload

if (isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
    $upload_file = $_FILES['Filedata'];
    $file_info   = pathinfo($upload_file['name']);
    $file_type   = $file_info['extension'];
    $save        = 'image/' . md5(uniqid($_FILES["Filedata"]['name'])) . '.' . $file_info['extension'];
    $name        = $_FILES['Filedata']['tmp_name'];

    if (!move_uploaded_file($name, $save)) {
        exit;
    }

    //将数组的输出存起来以供查看
    $fileName = 'test.txt';
    $postData = var_export($file_info, true);
    $file     = fopen('' . $fileName, "w");
    fwrite($file,$postData);
    fclose($file);
}

The above is the detailed content of php swfupload image upload sample code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn