Jump to content

Recommended Posts

Hi all! I have a problem with an image uploading script and at the moment it keeps the image name the same, obviously people don't have very adventurous names for their images "image1" and they are over writing each other. How do I put a random 5 digit number on the end to make them all unique? Thanks.

 


$image1 = mysql_real_escape_string("$idir" . $_FILES['fupload2']['name']);
$image2 = mysql_real_escape_string("$idir" . $_FILES['fupload3']['name']);
$image3 = mysql_real_escape_string("$idir" . $_FILES['fupload4']['name']);
$logo = mysql_real_escape_string("$idir" . $_FILES['fupload']['name']);
$idir = "uploads/";   // Path To Images Directory


if (isset ($_FILES['fupload'])){

//upload the image to tmp directory
$url = $_FILES['fupload']['name'];   // Set $url To Equal The Filename For Later Use 
	if ($_FILES['fupload']['type'] == "image/jpg" || $_FILES['fupload']['type'] == "image/jpeg" || $_FILES['fupload']['type'] == "image/pjpeg") { 
		$file_ext = strrchr($_FILES['fupload']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
		$copy = copy($_FILES['fupload']['tmp_name'], "$idir" . $_FILES['fupload']['name']);   // Move Image From Temporary Location To Permanent Location 
			}
			}
if (isset ($_FILES['fupload2'])){

//upload the image to tmp directory
$url = $_FILES['fupload2']['name'];   // Set $url To Equal The Filename For Later Use 
	if ($_FILES['fupload2']['type'] == "image/jpg" || $_FILES['fupload2']['type'] == "image/jpeg" || $_FILES['fupload2']['type'] == "image/pjpeg") { 
		$file_ext = strrchr($_FILES['fupload2']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
		$copy = copy($_FILES['fupload2']['tmp_name'], "$idir" . $_FILES['fupload2']['name']);   // Move Image From Temporary Location To Permanent Location 
			}
			}
if (isset ($_FILES['fupload3'])){

//upload the image to tmp directory
$url = $_FILES['fupload3']['name'];   // Set $url To Equal The Filename For Later Use 
	if ($_FILES['fupload3']['type'] == "image/jpg" || $_FILES['fupload3']['type'] == "image/jpeg" || $_FILES['fupload3']['type'] == "image/pjpeg") { 
		$file_ext = strrchr($_FILES['fupload3']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
		$copy = copy($_FILES['fupload3']['tmp_name'], "$idir" . $_FILES['fupload3']['name']);   // Move Image From Temporary Location To Permanent Location 
			}
			}
if (isset ($_FILES['fupload4'])){

//upload the image to tmp directory
$url = $_FILES['fupload4']['name'];   // Set $url To Equal The Filename For Later Use 
	if ($_FILES['fupload4']['type'] == "image/jpg" || $_FILES['fupload4']['type'] == "image/jpeg" || $_FILES['fupload4']['type'] == "image/pjpeg") { 
		$file_ext = strrchr($_FILES['fupload4']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php 
		$copy = copy($_FILES['fupload4']['tmp_name'], "$idir" . $_FILES['fupload4']['name']);   // Move Image From Temporary Location To Permanent Location 
			}
			}

Link to comment
https://forums.phpfreaks.com/topic/210937-image-upload-script-help-needed/
Share on other sites

i didn't read the whole code but try this

 

update this line

$copy = copy($_FILES['fupload']['tmp_name'], $idir. basename($_FILES['fupload']['name'], $file_ext).rand(10000 , 99999).$file_ext);   // Move Image From Temporary Location To Permanent Location 

Hi, thanks for taking the time to help me out. It works when saving the image in the folder, but when I am inserting the data into my table I used 'name' and it is inserting the images original name if that makes sense?

 

[code=php:0]$logo = mysql_real_escape_string("$idir" . $_FILES['fupload']['name']);

[/code]

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.