divinity02 Ответов: 1

Как создать страницу на PHP для загрузки картинок


привет яблока

I have an question, i am creating a webpage for an assignment and one is that I have to create a page for the users to upload their pictures for other to see and take but I would like to know how do i go about doing that in php. can someone point me in the right direction. or at least give me a head start.


Что я уже пробовал:

I have an question, i am creating a webpage for an assignment and one is that I have to create a page for the users to upload their pictures for other to see and take but I would like to know how do i go about doing that in php. can someone point me in the right direction. or at least give me a head start.

1 Ответов

Рейтинг:
1

DavidCorbin_1978

Надеюсь, это поможет.


<form action="accept-file.php" method="post" enctype="multipart/form-data">
Your Photo: <input type="file" name="image" size="25" />
<input type="submit" name="submit" value="Submit" />
</form>
After you create this HTML form, you’ll now have to write a PHP script in order to process the PHP file upload. Below you’ll find PHP file upload script code for the same.
PHP Script:
//if they DID upload a file...
if($_FILES['image']['name'])
{
//if no errors...
if(!$_FILES['image']['error'])
{
//now is the time to modify the future file name and validate the file
$new_file_name = strtolower($_FILES['image']['tmp_name']); //rename file
if($_FILES['image']['size'] > (1024000)) //can't be larger than 1 MB
{
$valid_file = false;
$message = 'Oops! Your file\'s size is to large.';
}

//if the file has passed the test
if($valid_file)
{
//move it to where we want it to be
move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/'.$new_file_name);
$message = 'Congratulations! Your file was accepted.';
}
}
//if there is an error...
else
{
//set that to be the returned message
$message = 'Ooops! Your upload triggered the following error: '.$_FILES['image']['error'];
}
}

//you get the following information for each file:
$_FILES['field_name']['name']
$_FILES['field_name']['size']
$_FILES['field_name']['type']
$_FILES['field_name']['tmp_name']