bigjoe11a wrote:Well like I said. That video tutorial will show you how to do all that. It will show you the images and a description from my mysql database. Let me know if you find the right one.
I can find videos on youtube but none of them actually helps with my problem to be honest!
Here is the issue that I have now! The images are uploaded into a directory on the server but before they are uploaded they are randomly renamed so they don't over write eachother.
But on the MySql database they are shown as their original name. for example: the image "myImage.png" has been uploaded and it has been renamed successfuly to something like 312344146.png.
BUT
when I look inot the mysql database it will show the image by its original name "myImage.png".
and thats why I cannot display the images on my page because they are renamed but in the database they kept their original name!! So what I need to do is that to do the same renaming function when they are saved in the database.
Here is my upload.php code:
- Code: Select all
<?php
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
//This gets all the other information from the form
$uploaded=($_FILES['uploaded']['name']);
$vehichle=$_POST['vehichle'];
$contact=$_POST['contact'];
// Connects to your Database
mysql_connect("localhost", "username", "password") or die(mysql_error()) ;
mysql_select_db("database") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$vehichle', '$contact', '$uploaded')") ;
//This applies the function to our file
$ext = findexts ($_FILES['uploaded']['name']) ;
//This line assigns a random number to a variable. You could also use a timestamp here if you prefer.
$ran = rand () ;
//This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended.
$ran2 = $ran.".";
//This assigns the subdirectory you want to save into... make sure it exists!
$target = "images22/";
//This combines the directory, the random file name, and the extension
$target = $target . $ran2.$ext;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file has been uploaded as ".$ran2.$ext;
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
?>
Any sugesstions?
Cheers