The following guide shows the steps to implement Uploader Control into PHP applications. If you haven't downloaded the software, please download it from here.
-
Deploying Uploader Client files.
The "phpuploader" folder and all file it contains (located in the archive) should be deployed to http://{your site}/{your application}/phpuploader/ on your web site.
-
Adding Uploader into PHP page.
- //Step 1: Register Uploader component to your page
- <?php require_once "phpuploader/include_phpuploader.php" ?>
- <html>
- <body>
- <form id="form1" method="POST" action="upload.php">
- <?php
- //Step 2: Create Uploader object.
- $uploader=new PhpUploader();
- //Step 3: Set a unique name to Uploader
- $uploader->Name="myuploader";
- //Step 4: Render Uploader
- $uploader->Render();
- ?>
- </form>
- </body>
- </html>
This form sends data to the file "upload.php", which is what we will be creating next to actually upload the file.
-
Saving the Uploaded File.
The "upload.php" file contains the code for uploading a file. When the uploader.php file is executed, the uploaded file exists in a temporary storage area on the server. If the file is not moved to a different location it will be removed! To store the uploaded file we need to copy it to a different location using CopyTo or MoveTo method.
- //Step 1: Register Uploader component to your page
- <?php require_once "phpuploader/include_phpuploader.php" ?>
- <html>
- <body>
- <?php
- //Gets the GUID of the file based on uploader name
- $fileguid=@$_POST["myuploader"];
- if($fileguid)
- {
- //get the uploaded file based on GUID
- $mvcfile=$uploader->GetUploadedFile($fileguid);
- if($mvcfile)
- {
- //Gets the name of the file.
- echo($mvcfile->FileName);
- //Gets the temp file path.
- echo($mvcfile->FilePath);
- //Gets the size of the file.
- echo($mvcfile->FileSize);
- //Copys the uploaded file to a new location.
- $mvcfile->CopyTo("/uploads");
- //Moves the uploaded file to a new location.
- $mvcfile->MoveTo("/uploads");
- //Deletes this instance.
- $mvcfile->Delete();
- }
- }
- ?>
- </body>
- </html>