change name of a file being uploaded

Posted on 2005-04-11
Last Modified: 2010-04-17
this is what I have right now:

      $uploaddir = '/home/httpd/vhosts/';
      $uploadfile = $uploaddir . $_FILES['fieldOne']['name'];
      if (move_uploaded_file($_FILES['fieldTwo']['tmp_name'], $uploadfile)) {
            chmod ($uploadfile, 0755);
            print("Successful !");
      } else {
            print("Unsuccessful !");

this uploades the file properly as named on the computer, however, what I want is:


$next is a auto increment variable (works properly when inserting in DB only)
$_SESSION['clientId'] is the client id variable (works properly when inserting in DB only)
then the name of the image as named on the computer (works properly)
in between variables I would like a - (hyphen)


Question by:jtrudeau
    LVL 55

    Accepted Solution

    $uploadfile = $uploaddir . $_FILES['fieldOne']['name'];

    According to your explanation, would be:
     $uploadfile = $uploaddir . $next . "-" . $_SESSION['clientId']."-".$_FILES['fieldOne']['name'].".jpg"

    Author Comment

    I could have swore I tried that exact same thing and it didnt work I guess I was missing something somewhere, because yourw worked.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now