Jump to content

[SOLVED] Give Image Unique Name


Ell20

Recommended Posts

Hi,

 

I have an upload script which successfully uploads a picture and creates a thumbnail of the picture and stores the information in the database.

 

I have just used the file_exists function to give out an error message if a user uploads a photo which has the same name as another photo in the directory.

 

But what I would ideally like to do is to create some kind of unique image name so that is either unlikely or impossible to have 2 images with the same name.

 

I have had a look at various unique image naming scripts online but none of them seem to fit my code as I am using the copy function.

 

copy ($_FILES['imagefile']['tmp_name'], "/home/mysport/public_html/images/UserImgs/".$_FILES['imagefile']['name']) or die ("Could not copy");

 

Appreciate any help.

Link to comment
https://forums.phpfreaks.com/topic/83775-solved-give-image-unique-name/
Share on other sites

Thanks its worked as I have echoed the name of the file but I also have an error:

 

An error occured in script /home/mysport/public_html/includes/functions.php on line 87: Undefined index: extension

 

Line 87 of functions.php:

 

if ( strtolower($info['extension']) == 'jpg' )

 

Thanks

gallery.php
<?php
if (isset($_POST['submit'])) {

if ($_FILES['imagefile']['type'] == "image/jpeg"){
copy ($_FILES['imagefile']['tmp_name'], "/home/mysport/public_html/images/UserImgs/".$_FILES['imagefile']['name'] = md5($_FILES['imagefile']['name'] . rand()) . $_FILES['imagefile']['name']) or die ("Could not copy");
echo '<h3><center>Picture Uploaded!</center></h3>';

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.