Jump to content

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>';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.