Information

Give your form element the id cat photo form

Give your form element the id cat photo form


We are searching data for your request:

Forums and discussions:
Manuals and reference books:
Data from registers:
Wait the end of the search in all databases.
Upon completion, a link will appear to access the found materials.

Give your form element the id cat photo form, and call the form submit method like this:

<,form action="submit_photo.php" id="cat-photo-form" method="post" enctype="multipart/form-data">,

<,input type="file" name="catphoto" id="catphoto" />,

<,/form>,

...

if(isset($_POST['catphoto'])){

$catphoto = $_FILES['catphoto']['name'],

$catphoto_tmp = $_FILES['catphoto']['tmp_name'],

$cat_id = $_POST['cat_id'],

if(!empty($cat_id)){

$update_cat = $db->,query("UPDATE cats SET photo='$catphoto_tmp' WHERE cat_id = $cat_id,"),

if($update_cat){

echo 'Your cat photo has been uploaded!',

}

}

}

You have to upload the form with enctype="multipart/form-data", otherwise you can't send the file through the form.

To read the file and update the database:

$upload_dir = 'uploads/',

if(!empty($_FILES['catphoto'])){

$new_name = $upload_dir.$_FILES['catphoto']['name'],

$tmp_name = $_FILES['catphoto']['tmp_name'],

$error = $_FILES['catphoto']['error'],

$size = $_FILES['catphoto']['size'],

if($error === UPLOAD_ERR_OK){

if(!empty($new_name)){

if(move_uploaded_file($tmp_name, $new_name)){

echo 'The cat photo has been successfully uploaded',

}

}

}

}

Read more: http://php.net/manual/en/features.file-upload.post-method.php


Video, Sitemap-Video, Sitemap-Videos