Jump to content

Upload image, make new random filename, add new name in MySQL


redgtsviper

Recommended Posts

Ok, I don't know if I am doing this right but and help would be great, I am still very green @ php. below you will find my code. In this page I have established a database connect already. the file uploads perfectly with my new name. My real question is how can I put my new file name in my database form my variable $newName. What would be the proper code to do this?

 

 

<?php

 

// Generate Random Number

srand(time());

$random = (rand()%99999999);

 

// Add Random Number to First of File Name

$newName="$random"."_"."$file_name";

 

// Copy to Fold Append New File Name

if($file_name !="")

{

copy ("$file", "images_upload/$newName")

or die ("could not copy file");

}

else { die(); }

 

//DISPLAY INPUT/OUTPUT

echo"Old File Name is: $file_name<br>";

echo"File Size is: $file_size<br>";

echo"File Type is: $file_type<br>";

echo"Random Number is: $random<br>";

echo"New File Name is: $newName";

?>

You really should put all code inside the [ code ] [ /code ] tags.

 

One way (I am just creating this in my head since you did not post any SQL what so ever) is this:

 

<?php
// mysql connection started

mysql_query("UPDATE tabl_name SET filename = '".$newName."' WHERE fileid = '".$fileid."'");

?>

 

This is assuming you have a fileid in the database to identify the file, if not put your identification field there. Either way that is how you update a field using MySQL.

 

--FrosT

Here is my SQL code, can you tell me why it is not working

 

 

<?php require_once('Connections/siteData.php'); ?>

<?php

mysql_select_db($database_siteData, $siteData);

$query_Recordset1 = "SELECT * FROM images";

$Recordset1 = mysql_query($query_Recordset1, $siteData) or die(mysql_error());

$row_Recordset1 = mysql_fetch_assoc($Recordset1);

$totalRows_Recordset1 = mysql_num_rows($Recordset1);

 

mysql_query("INSERT INTO images VALUES ('$newNmae')");

 

?>

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.