answersLogoWhite

0


Best Answer

Hope your requirement is to upload a file to server .

follow this code.

$files=array();

$file=handleUpload($_FILES);

function handleUpload($upload_file){

if(!$upload_file) return;

$files=array();

$file->file_orig_name = $upload_file['name'];

$file->file_size = $upload_file['size'];

$path_parts = pathinfo($file->file_orig_name);

$file->file_extension = strtolower($path_parts['extension']);

$file->file_mime_type = $upload_file['type'];

$file->file_tmp_name = $upload_file['tmp_name'];

return $files;

}

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you create a script to upload a file in PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you create a PHP script?

To create a PHP script all you have to do is create a new file, then save the file as "filename.php". It must have a .php file extension.After that open the file and put in the PHP tags like shown.Then you write your PHP script within those tags and upload to your web space and check it out.


What is the Malay-utf-8.inc. php file?

This particular file is a file specific to the PHP program or script you are using. It is not a "php system file".


How do you upload an image using PHP?

You upload the image in HTML using a form that includes the following field <input type="file" name="fileUpload" /> After the form is submitted, you can access it with the $_POST variable as $_POST['fileUpload'] http://www.tutorialsscripts.com/free-php-scripts/file-and-directory-script/image-upload.php


How do you create a web mail script using PHP?

You can use phpMailer() Or, you can use mail() PHP function to send emails via PHP script.


Can you sen a code to upload photo in javascript or php?

Please go to www.google.com, and search for "php upload photo script" or something alike. I'm sure you'll find somthing there.


How do you find version of PHP in uniform server?

The easiest way is to create a file with a name ending in .php (such as info.php), containing only these 3 lines: <? phpinfo(); ?> Upload this file to your web space and access it using your browser. It will show a lot of information about your webserver and the php version running on it.


Are there any tags in HTML to upload or download a file?

You will need to use a script such as PHP or ASP for uploading purposes. You can use an anchor tag for downloading:right click and choose 'save as' to download


How-to download php videos?

A PHP file will not be a video. Videos are commonly .wmv, .mov, .mp4, etc. PHP is a server scripting programming language. Since a PHP file is completely parsed on the server, you cannot download a PHP file, unless you use another script to enforce the download. But even that approach requires that the script be on the same server as the target one.


How do you create a DIV type file using PHP?

A file with the DIV file extension is a DivX Movie file, it cannot be created with PHP. PHP is a web programming language for web site building.


What is the effect of the return instruction when used in a included PHP script?

Return to the parent script while ignoring the rest of the included file


What is an example script that would upload a file using PHP?

Here is an example script: <html> <head><strong><div align="center">File Upload!!</div></strong></head> <body> <form name="form1" enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" > File: <input type="file" name="file" id="file" /> <input type="submit" name="submit" value="Upload" > </form> <?php if(isset($_POST['submit'])) { if ($_FILES['file']['error'] > 0) { echo "Error: " . $_FILES['file']['error'] . "<br />"; } else { echo "Upload: " . $_FILES['file']['name'] . "<br />"; echo "Type: " . $_FILES['file']['type'] . "<br />"; echo "Size: " . ($_FILES['file']['size'] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES['file']['tmp_name']; if (file_exists("../" . $_FILES["file"]["name"])) { // Checks if the file already exists echo "<br>".$_FILES["file"]["name"] . " already exists. "; } else { // If file does not exists, moves the file to folder move_uploaded_file($_FILES["file"]["tmp_name"], "../" . $_FILES["file"]["name"]); echo "<br>Stored in: " . realpath("../" . $_FILES["file"]["name"]); } } } ?> </body> </html


What is harder to create from scratch a php amazon clone script or a php youtube script?

In Core-PHP I would assume both are difficult. But between the two Amazon clone would be a bit harder. Ideal thing would be to use Magento to create an Amazon type site.