Code: Select all
<form action="upload.php" method="post" ENCTYPE="multipart/form-data">
File: <input type="file" name="file" size="30"> <input type="submit" value="Upload!">
</form>Upload PHP
Code: Select all
<?php
// ==============
// Configuration
// ==============
$uploaddir = "uploads"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
// ==============
// Upload Part
// ==============
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']);
}
print "Your file has been uploaded successfully! Yay!";
?>I found this code on-line and have been using it, without completely understanding everything about it, to upload images to my server. My questions:
1. What do I need to do in order that the new uploaded file will be saved to a name and extension that I have assigned? (force a name change. ie xxxnewuploaded.jpg saves as predeterminedfilename.jpg)
2. I am obviously a noobie, would anyone like to help me understand what the basic elements/structure of the strings in this code are? For example, $_FILES is an array? What is the structure of an array?
My objective: I am building a web-site for a friend who knows nothing about coding, etc. He wants to be able to upload pictures, but I want to control cludder on his server. Therefore- I want each new image to replace the old as the same name.
Thanks!