Adding GD file size and renaming to upload php images script

I have this script that allows you to upload an image, and then the pointer is stored in the database in a file on the file system. I got this script from another StackOverflow question, and it does almost everything I need, except for two things. The first thing I need is to resize the images, and the second part that I just read about is to rename the file to prevent user errors, etc.

Here is a download file that takes form data from the user input form and writes the data to the database and image in the image catalog.

 <?php

//This is the directory where images will be saved
$target = "your directory";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$name=$_POST['nameMember'];
$bandMember=$_POST['bandMember'];
$pic=($_FILES['photo']['name']);
$about=$_POST['aboutMember'];
$bands=$_POST['otherBands'];


// Connects to your Database
mysql_connect("yourhost", "username", "password") or die(mysql_error()) ;
mysql_select_db("dbName") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("INSERT INTO tableName (nameMember,bandMember,photo,aboutMember,otherBands)
VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
+3
source share
1 answer

, , GD. , .

http://www.spotlesswebdesign.com/blog.php?id=1

, .

do {
    $filename = uniqid().'jpg';
} while (file_exists('image/path/'.$filename);
0

Source: https://habr.com/ru/post/1786208/


All Articles