Jump to content

Image to folder, then entry in database ...


nvee

Recommended Posts

Hey guys.

 

This is not that much a code help, but I am fairly new with PHP and have never done a image upload script yet. I notice online that the majority of tutorials shows you how to upload images to a database. I want to upload the file, generate a random new name for the file and write that to a database.

 

I have not worked that much with file() yet, so does anyone know of a fairly simple tutorial (or even assistance here) on how to do this.

 

I have already created the form which writes to the database. It has a file field whose id is img.

 

 

Link to comment
https://forums.phpfreaks.com/topic/181716-image-to-folder-then-entry-in-database/
Share on other sites

You can use the move_uploaded_file to save the uploaded file to a specific directory.

 

<?php

$file = $_FILES['my_file_field']['tmp_name'];
$destination = 'uploaded/files/';
$filename = 'new_image_upload.jpg';

if (move_uploaded_file($file, $destination.$filename))
{
    echo "File has been uploaded";
}
else echo "File could not be uploaded, check destination permissions.";

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.