Closed

PHP image upload help needed

This project received 30 bids from talented freelancers with an average bid price of $30 USD.

Get free quotes for a project like this
Employer working
Skills Required
Project Budget
$30 - $250 USD
Total Bids
30
Project Description

Hi,

I need a very small help. NO high ballers please as this is a very very small job.

I don't need you to do anything, I just need you to tell me what to do and I will do it myself.

here is the exact details:

I have a PHP code that will allow me to upload images onto my server and it will renames the files so they won't overwrite each other.

I need to know how I can save the renamed files name on the mysql databse.

here is my PHP code:

<?php

function findexts ($filename)

{

$filename = strtolower($filename) ;

$exts = split("[/\.]", $filename) ;

$n = count($exts)-1;

$exts = $exts[$n];

return $exts;

}

//This gets al=$_POST['vehichle'];l the other information from the form

$vehichle_name=$_POST['vehichle_name'];

$upload=($_FILES['uploaded']['name']);

$vehichle=$_POST['vehichle'];

$contact=$_POST['contact'];

// Connects to your Database

mysql_connect("localhost", "myUsername", "pass") or die(mysql_error()) ;

mysql_select_db("databaseName") or die(mysql_error()) ;

//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.";

}

//Writes the information to the database

mysql_query("INSERT INTO `employees` VALUES ('$vehichle_name', '$vehichle', '$contact', '$upload')") ;

?>

at the moment the script above will upload the image and renames it and saves it in folder images22 successfuly.

i.e. Uploades [url removed, login to view] and gives it a random name like [url removed, login to view] and saves as as 234523123123.png. this is well and good but when I look into my databse it showes the image with its original name which is [url removed, login to view] instead of [url removed, login to view]!!

can someone please help me with this as I have been trying to do this for 2 days with no avail.

cheers

Looking to make some money?

  • Set your budget and the timeframe
  • Outline your proposal
  • Get paid for your work

Hire Freelancers who also bid on this project

    • Forbes
    • The New York Times
    • Time
    • Wall Street Journal
    • Times Online