Uploading images to a PHP script

hello. I just started learning Java... so... sorry for elementary questions.
I would appreciate it if someone could give me a clue as to what to read in the Java documentation regarding to uploading images to a PHP script on the server.
I dont mind researching by myself but it would be great if someone could give me class names and method names that accomplish uploading image files.
Links to articles or forum threads would be great too!
I really appreciate it.
Thank you
Ivan

just a guess... its URLConnection a good way to go to implement image uploading functionality?
thank you

Similar Messages

  • Uploading image in document servers scripts/smartforms

    Hi,
       Can anyone of help me to upload the image(.jpg)  in doucment server. ?
    Regards,
    Ganesh .

    Steps:
    1.Go to transaction SE78 (Administration of Form Graphics). 
    2. Double-click on u201CGRAPHICSu201D node and click on u201CImport (F5)u201D to import the image. 
    3. Select the file name by using the F4 functionality available. Name your graphic and enter a short description. If you have color image, select the radio button u201CColor Bitmap imageu201D.  Click on tick mark to proceed. 
    4. The graphic is imported and is stored in u201CBusiness Document Serveru201D.  You can test this by selecting print preview.
    Regards,
    JOy.

  • Problem uploading images with php script.

    As a webdebdesigner i developped a cms system to upload images with php to a mysql database. Firefox version 5.0.1 for MAC and earlier have no problems with uploading through the script. But after that version it is impossible to upload images bigger then 250kb. The page where the customer chooses his image for upload stalls and the form is not sent to the actual upload script, which should validate and process the image.
    This problem only occurs in Firefox, all other browsers work just fine!
    On top of that: Giving feedback to firefox not possible for MAC.

    Try posting at the Web Development / Standards Evangelism forum at MozillaZine. The helpers over there are more knowledgeable about web site development issues with Firefox. <br />
    http://forums.mozillazine.org/viewforum.php?f=25 <br />
    You'll need to register and login to be able to post in that forum.

  • PHP script for form to upload 2 files to FTP

    Hi,
    I have scoured the internet for quite a while now looking for
    a free php script that will enable me to:
    1. Put a form on a page that has two uplaod boxes for a
    client to upload two file svia theeir browser
    2.The files will be one image (jpg) and one pdf
    3. The files will always (each day) be called headshot.jpg
    and resume.pdf
    4. The script must allow the files on the server to be
    overwritten by the new files of the same name each day
    I have found MANY scripts, som eof which i can get to work,
    but they were too sofisticated (checked for many things taht i was
    not concerned for, didnt allow files to be overwritten, changed
    directories of where the files were uplaoded to, changed the file
    names automatically) and many that i wasnt able to get to work.
    I just need something simple like the above. Unfortunately I
    am no scripter, so when i tried to decifer the ready made scripts
    and rearrange them to suit my needs, i messed things up.
    Thanks immensely in advance of anyone who canb offer m eany
    help or point me in a better direction. I wasnt sure where to post
    this query/help plea.
    Cheska

    Go to
    http://www.php.net and read about
    file uploads there. You will find
    several scripts that will work just fine for you.
    Or try this -
    <?php
    //places files into same dir as form resides
    if(isset($_POST['Submit'])) {
    $target=$_SERVER['DOCUMENT_ROOT']."/uploads";
    foreach ($_FILES["files"]["error"] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
    $tmp_name = $_FILES["files"]["tmp_name"][$key];
    $name = $_FILES["files"]["name"][$key];
    if(move_uploaded_file($tmp_name, "$target/$name")}
    print "Upload completed";
    else
    print "Upload failed";
    ?>
    <body>
    <form action="" method="post"
    enctype="multipart/form-data">
    <p>Pictures:
    <input type="file" name="files[]" />
    <input type="file" name="files[]" />
    <input type="submit" name="Submit" value="Send" />
    </p>
    </form>
    This assumes that the incoming files will be properly named,
    and that the
    upload destination is a folder called "/uploads".
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "ccesca" <[email protected]> wrote in
    message
    news:[email protected]...
    > Hi,
    >
    > I have scoured the internet for quite a while now
    looking for a free php
    > script that will enable me to:
    >
    > 1. Put a form on a page that has two uplaod boxes for a
    client to upload
    > two
    > file svia theeir browser
    > 2.The files will be one image (jpg) and one pdf
    > 3. The files will always (each day) be called
    headshot.jpg and resume.pdf
    > 4. The script must allow the files on the server to be
    overwritten by the
    > new
    > files of the same name each day
    >
    > I have found MANY scripts, som eof which i can get to
    work, but they were
    > too
    > sofisticated (checked for many things taht i was not
    concerned for, didnt
    > allow
    > files to be overwritten, changed directories of where
    the files were
    > uplaoded
    > to, changed the file names automatically) and many that
    i wasnt able to
    > get to
    > work.
    >
    > I just need something simple like the above.
    Unfortunately I am no
    > scripter,
    > so when i tried to decifer the ready made scripts and
    rearrange them to
    > suit my
    > needs, i messed things up.
    >
    > Thanks immensely in advance of anyone who canb offer m
    eany help or point
    > me
    > in a better direction. I wasnt sure where to post this
    query/help plea.
    >
    > Cheska
    >
    >
    >

  • Uploading a file using a php script while running application with LCDS

    Hi! I developping an application under Flex 2 / Java -
    running on LCDS / JRun server.
    I'm trying to add uploading capabilities. I'm using a php
    script for the upload part.
    First, I just try to put script on the app directory. Doesn't
    work.
    After that I set up an apache server from where I put a small
    web site with my script. It's telling me that my file is
    succesfully uploaded, but I can't find the file. The apache log
    give me no error.
    Someone can help me?

    Originally, I had problems w/ the file being placed in
    C:/whatever.ext b/c I wasn't using relative paths.
    This is the code I use:
    $MAXIMUM_FILESIZE = 1024 * 1024 * 2; // 2MB
    $newFileLoc = "./wherever/file.jpg"
    if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE) {
    move_uploaded_file($_FILES['Filedata']['tmp_name'],
    "./temporary/".$_FILES['Filedata']['name']);
    rename( "./temporary/".$_FILES['Filedata']['name'],
    $newFileLoc );
    chmod( $newFileLoc, 0777 );
    Modified from this article by Adobe:
    http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=17_Networking_and_communications_173_6.html

  • Upload images to a MySQL database (PHP)?

    Ok so i don't get any error but is not doing anything to my database, any suggestions?
    <body>
    <form action="image.php" method="POST" enctype="multipart/form-data">
    File:
        <input type="file" name="image" />
        <input type="submit"  value="Upload"/>
    </form>
    <?php       
    //Conect to database
    $mydatabase = mysql_pconnect($hostname_mydatabase, $username_mydatabase, $password_mydatabase) or trigger_error(mysql_error(),E_USER_ERROR);
    mysql_select_db("database")or die (mysql_error());
    //file properties
    $file = $_FILES['image']['tmp_name'];
    if (!isset($file))
              echo"PLease select a file";
    else
    $image=addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name=addslashes($_FILES['image']['name']);
    $image_size=getimagesize($_FILES['image']['tmp_name']);
    if($image_size==FALSE)
              echo "That's not an image.";
    else
              if ($insert = mysql_query("INSERT INTO table VALUES ('$image_name', '$image')"))
              echo "Problem uploading image.";
              else
    ?>
    </body>

    Why do you want the binary value of the image?
    Just save the image name as you are and then move the uploaded file to the proper folder on your server.
    http://php.net/manual/en/function.move-uploaded-file.php

  • Help with file uploader, php script, Windows Authentication

    I am trying to setup a really basic web-based file uploader that I will expand upon later. I have the flex application working well enough (very basic). However, I have a php script in a secure folder using windows authentication. When I try to send the file to the script, it doesn't seem to like my credentials, and refuses to do anything. I do not get an error message; just nothing happens.
    My questions are:
    Does anybody know where I should've looked before posting this thread?
    Do I even have PHP set up correctly? (At first I just made a txt file and put a .php extension on it, then I tried to setup PHP on the server, but it was a little confusing for me)
    Is Windows Authentication the problem?
    I do plan on implementing SQL Server in the future (to keep track of Files and user-defined attributes for files), but I do not want to store the files in SQLserver, just their pathnames.
    Is there a simple way to use ColdFusion (for free) to acheive this end?
    I am somewhat experienced at coding applications, but am totally new to server-side scripts.
    This is my php script:
    <?php
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $fileName = $_FILES['Filedata']['name'];
    $fileSize = $_FILES['Filedata']['size'];
    move_uploaded_file($tempFile, "./" . $fileName);
    ?>
    This is my flex application:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Script>
         <![CDATA[
         private var fileRef:FileReference
         private var uploadFilePath:String
         private function selectFile():void
              fileRef = new FileReference();
              fileRef.addEventListener(Event.SELECT, fileRef_select);
              fileRef.browse();
         private function fileRef_select(evt:Event):void
              fileRef.upload(new URLRequest("http://SERVERLOCATION/PDFUploader.php"));
         ]]>
    </fx:Script>
         <s:Button top="30" left="5" label="Browse" click="selectFile()"/>
    </s:Application>
    Thanks to any who take the time to respond.

    Hey, so far all I have found is this tutorial.. I'm about to try it out
    http://www.smartwebby.com/Flash/external_data.asp

  • Using the fileReference class to upload image

    I've been using the loadVars to upload text and pass
    variables to php and onto the server. I've begun using the Flash
    Filereference class so an image can be uploaded directly from a
    Flash movie, not involving an html form. But within the
    Filereference script I can't figure out how to pass a variable to
    php as I did using loadVars method. I've tried a number of hit-miss
    ways but they've all been misses.
    Right now the path to save an image file is "hard-wired" into
    the php script. This is the var that I want to pass.
    thanks
    The script is here if you need to take a peek:

    Someone else asked about this recently. I think the answer
    you're after is here:
    http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=288&threadid =1317799
    That's for POST data.
    If you want to send additional GET data you could just append
    it to the url.

  • How do i create a website that allows customer to upload images and text?

    I need some help i have a friend who has asked me if i can create a website that allows them to upload their own images and text at their leisure.
    His company is in the car sales trade so they need to regularly be updating their stock, and this needs to be done by somebody with limited computer knowledge so ease of use is fairly important.
    I am using dreamweaver cs4 on a G5 Imac running Snow leopard 10.6.8, my skills are limited to creating uncomplicated websites but i am very keen to learn, i am aware of content management systems such as Druplal but have zero knowledge on how to use these.
    Any assistance would be greatly appreciated
    Andy Barrington
    www.andybarrington.com

    You can take a read here
    http://www.hotscripts.com/category/php/scripts-programs/classified-ads/autos/
    http://icloudcenter.com/auto-dealer-car-sales-script.htm
    Although putting together a form that would upload images and all the descriptions required seems like a fairly straghtforward project, depending on your current skill set.
    Gary

  • User Uploaded Image won't display on Mac OSX

    I am experiencing something very strange with user uploaded
    images on Mac OSX, latest Debug Flash Player 9, Safari and Firefox
    2. Everything works fine on Windows (XP and Vista) on all major
    browsers.
    A user selects a local image to upload. The file gets
    uploaded to server, resampled, saved to a public location, and a
    response is sent back to the Flash Player in the form of a JSON
    object. The response contains the URL to the uploaded image on the
    server. The Flash Player downloads the image and adds the Loader to
    a sprite that is already on the stage. All appropriate events are
    fired. The progress events show that the image is downloading, and
    the complete and init events are both fired. Using the Charles Web
    debugging Proxy I can verify that everything is working correctly
    (upload and download), and no security violations are occuring.
    Charles even shows the actual image that gets downloaded. However,
    on Mac, the image doesn't display (stays blank, as if it's an empty
    sprite), whereas on PC/Windows the image displays fine.
    I have placed a crossdomain file in the appropriate location
    - even though it is never requested as I don't try to do anything
    with the image's bitmap data.
    Unfortunately, I haven't had a chance to create a new project
    to test this out in, but will do as soon as I can, and post a link.
    Any ideas?
    Many thanks,
    Shaun.

    We had a similar problem, maybe it is related to this (it was
    done in as2, but the real problem was outside flash)
    flash took an enormous time to display thumbs for a gallery
    of images.. and directly in ff on osx, the thumb (about 100x100 px)
    would load only half way.. and again wait for about half a minute
    or more.. and then display. In flash the thumb would remain blank
    until the loading was over.. that is for about half a minute or
    more.
    What this turned out to be, was that the php script on the
    server somehow returned header information that the image had the
    dimensions of the full-sized image. So after all the data for the
    thumb downloaded, the client (browser or flash) would just wait
    until a predefined timeout..
    Since you are resizing uploaded images I thought this could
    be one of the possible reasons, maybe the flash player for osx and
    for windows handle such "missing data" cases differently.

  • Passing variable to PHP script

    Hi,
    I'm new to Oracle&APEX...
    I would like to upload a file to server filesystem, but I could not fid a way this to be done via APEX?
    (I somebody can give me a solution You are welcome)
    I know how this could be done in PHP so I created a script, but I need then to confirm to the database that the file is uploaded. To do this I need to have variable transferred to my PHP script.
    I've tried to build a button to pass the value with ?var=:P5_value, but only "P%_value" is passed as text not the value of this variable.
    How this can be done?
    Any suggestions?

    Hello,
    You should use the webdav functionality in XE.
    http://daust.blogspot.com/2006/03/where-are-images-of-application.html
    then you get the best of both worlds you get files in the database but they can be accessed as if they are in the filesystem.
    Note: APEX need to be replaced with HTMLDB for Oracle XEI have no idea what you are saying here, HTMLDB and APEX are the same thing.
    Carl

  • Multiple Upload Image Problem - Resize GIF files

    The Multiple Image Upload script seems to handle .jpg images without problems.
    However, .gif files return the error:
    "Error converting image (image resize). Image processing library not available or does not support operation. (imagemagick library is not working or not found)."
    The problem is caused by the fact that script that I'm using tries to pass a parameter that is not valid for gif processing:
    myimage.gif' '-quality' '80'
    The "quality" parameter works only for jpeg and .png files as described here:
    http://www.imagemagick.org/script/command-line-options.php#quality
    Please ensure that the script makes difference between .gif and .jpeg files and use the correct parameters so we can resize the images properly.
    Thanks in advance,
    Márcio

    Hi Marcio,
    >>
    Can you tell me the inconveniance of using GD instead of Imagemagick, or its, shortly similar?
    >>
    sorry, but never worked with ImageMagick so far, so I can´t compare
    >>
    The "quality" parameter works only for jpeg and .png files as described here
    >>
    yeah, it seems that this is a small bug in ADDT´s "includes/common/lib/image/KT_Image.class.php" file. Was just checking the code in there, and indeed it adds this extra parameter regardless the image type -- but I do have an idea how this file can be modified to not use this parameter if the file in question has the suffix ".gif".
    If you feel a little adventurous, I´ll happily invite you to modify some code in this file -- please let me know if you´re ready for some instructions. However, if so, please make a backup of this file first...
    Günter Schenk
    Adobe Community Expert, Dreamweaver

  • Code wont work when trying to upload image!

    My Code wont work when I try to upload an image to mysql. (Field in mysql is BLOB)
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>insert</title>
    <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
    <?php require_once('Connections/drama_database.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      if (PHP_VERSION < 6) {
        $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
      switch ($theType) {
        case "text":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;   
        case "long":
        case "int":
          $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case "double":
          $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case "date":
          $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
          break;
        case "defined":
          $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
          break;
      return $theValue;
    $editFormAction = $_SERVER['PHP_SELF'];
    if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO databaseimage (name, image) VALUES (%s, %s)",
                           GetSQLValueString($_POST['name'], "text"),
                           GetSQLValueString($_POST['image'], "double"));
      mysql_select_db($database_drama_database, $drama_database);
      $Result1 = mysql_query($insertSQL, $drama_database) or die(mysql_error());
    mysql_select_db($database_drama_database, $drama_database);
    $query_image = "SELECT * FROM databaseimage";
    $image = mysql_query($query_image, $drama_database) or die(mysql_error());
    $row_image = mysql_fetch_assoc($image);
    $totalRows_image = mysql_num_rows($image);
    ?>
    </head>
    <body>
    <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
    Name:  <span id="sprytextfield1">
      <label for="name"></label>
      <input type="text" name="name" id="name" />
      <span class="textfieldRequiredMsg">A value is required.</span></span>
      <p>
        <label for="image"></label>
        <input type="file" name="image" id="image" />
      </p>
      <p>
        <input type="submit" name="Upload" id="Upload" value="Upload" />
      </p>
      <input type="hidden" name="MM_insert" value="form1" />
    </form>
    <script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    </script>
    </body>
    </html>
    <?php
    mysql_free_result($image);
    ?>
    Any help would be very much appreciated!

    OK, that tutorial is different than what I assume you want. I suspect you want the ability to have users upload images and store the metadata of those images in a database, correct? That tutorial only shows how to upload to a specific location so the image can
    be displayed in an iframe.
    Search for "php file upload scripts" to see how to upload to a file system and store the metadata in the database.
    >and no, mostly i have used the dreamweaver features to avoid it as much as possible
    As you are seeing, DW code is very limited in what it can do. It also generates code that is not up to current standards,and is very difficult to work with if you need to modify it. Basically, it's junk. Forget it and learn how to read and write code. There are tons on tutorials on how to get started with PHP.  DW Server behaviors only seem like a time saver in the beginning. In the end, you'll end up wasting more time using them than learning how to code yourself.

  • Allowing visitors to upload images

    I would like to allow visitors to upload images to my site
    (.jpg and .gif ONLY). I have searched online and found a few
    different codes, but I would like to make it so that I would have
    to appove the images first (they would either be emailed to me or
    saved in the file manager). I also want it so people don't have to
    register before uploading an image. My site is not that popular.
    Does ANYONE know how to do this.. The closest thing I found
    was this page:
    http://www.abynex.com/imageupload.html
    I paid for the code, but don't completely understand it. Is
    there another way to get this action on my site.
    I don't know what PHP and MySQL are or how to use them. I do
    have a paid site and domain. Does this have anything to do with the
    website settings. Under that section, I see the Absolute Root Path
    & FTP Host/User .
    I am lost
    Thanks

    Don't you get any help files with the purchase?
    The first place to ask the question would be to the author of
    the script no?
    Nadia
    Adobe� Community Expert : Dreamweaver
    http://www.DreamweaverResources.com
    |Tutorials|SEO |CSS Templates
    http://www.csstemplates.com.au
    http://www.adobe.com/devnet/dreamweaver/css.html
    CSS Tutorials for Dreamweaver
    "Miss_Angela" <[email protected]> wrote in
    message
    news:ee3d1s$4rm$[email protected]..
    I would like to allow visitors to upload images to my site
    (.jpg and .gif
    ONLY). I have searched online and found a few different
    codes, but I would
    like
    to make it so that I would have to appove the images first
    (they would
    either
    be emailed to me or saved in the file manager).
    Does ANYONE know how to do this.. The closest thing I found
    was this page:
    http://www.abynex.com/imageupload.html
    I paid for the code, but don't completely understand it. Is
    there another
    way
    to get this action on my site.
    I don't know what PHP and MySQL are or how to use them. I do
    have a paid
    site
    and domain. Does this have anything to do with the website
    settings. Under
    that
    section, I see the Absolute Root Path & FTP Host/User .
    I am lost
    Thanks

  • Problem when trying to rename uploaded images using session value

    Hi,
    I have a form where 9 images are uploaded made into thumb nail size and then stored in a file. What I´m trying to do is rename those thumbnails from their original name to username_0, username_1, username_2 etc for each of the 9 thumbs. The username comes from the registration form on the same page. I have created a session variable for the username and am trying to use that to change to name of the image name, whilst my images are uploading and resizing the name stays as the original and not as the new username_$number. I have pasted relevant code below and would very much appreciate any help with this:
    <?php session_start();
    // check that form has been submitted and that name is not empty and has no errors
    if ($_POST && !empty($_POST['directusername'])) {
    // set session variable
    $_SESSION['directusername'] = $_POST['directusername'];
    // define a constant for the maximum upload size
    define ('MAX_FILE_SIZE', 5120000); 
    if (array_key_exists('upload', $_POST)) {
    // define constant for upload folder
    define('UPLOAD_DIR', 'J:/xampp/htdocs/propertypages/uploads/');
    // convert the maximum size to KB
    $max = number_format(MAX_FILE_SIZE/1024, 1).'KB';
    // create an array of permitted MIME types
    $permitted = array('image/gif','image/jpeg','image/pjpeg','image/png');
    foreach ($_FILES['photo']['name'] as $number => $file) {
    // replace any spaces in the filename with underscores
    $file = str_replace(' ', '_', $file);
    // begin by assuming the file is unacceptable
    $sizeOK = false;
    $typeOK = false;
    // check that file is within the permitted size
    if ($_FILES['photo']['size'] [$number] > 0 && $_FILES['photo']['size'] [$number] <= MAX_FILE_SIZE) {
    $sizeOK = true;
    // check that file is of a permitted MIME type
    foreach ($permitted as $type) {
    if ($type == $_FILES['photo']['type'] [$number]) {
    $typeOK = true;
    break;
    if ($sizeOK && $typeOK) {
    switch($_FILES['photo']['error'] [$number]) {
    case 0:
    include('Includes/create_thumbs.inc.php');
    break;
    case 3:
    $result[] = "Error uploading $file. Please try again.";
    default:
    $result[] = "System error uploading $file. Please contact us for further assistance.";
    elseif ($_FILES['photo']['error'] [$number] == 4) {
    $result[] = 'No file selected';
    else {
    $result[] = "$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png.";
    ................CODE BELOW IS THE INCLUDES FILE THAT MAKES AND TRIES TO RENAME THE THUMBS................................................
    <?php
    // define constants
    define('THUMBS_DIR', 'J:/xampp/htdocs/propertypages/uploads/thumbs/');
    define('MAX_WIDTH_THB', 75);
    define('MAX_HEIGHT_THB', 75);
    set_time_limit(600);
    // process the uploaded image
    if (is_uploaded_file($_FILES['photo']['tmp_name'][$number] )) {
    $original = $_FILES['photo']['tmp_name'][$number] ;
    // begin by getting the details of the original
    list($width, $height, $type) = getimagesize($original);
    // check that original image is big enough
    if ($width < 270 || $height < 270) {
    $result[] = 'Image dimensions are too small, a minimum image of 270 by 270 is required';
    else { // crop image to a square before resizing to thumb
    if ($width > $height) {
    $x = ceil(($width - $height) / 2);
    $width = $height;
    $y = 0;
    else if($height > $width) {
    $y = ceil(($height - $width) / 2);
    $height = $width;
    $x = 0;
    // calculate the scaling ratio
    if ($width <= MAX_WIDTH_THB && $height <= MAX_HEIGHT_THB) {
    $ratio = 1;
    elseif ($width > $height) {
    $ratio = MAX_WIDTH_THB/$width;
    else {
    $ratio = MAX_HEIGHT_THB/$height;
    if (isset($_SESSION['directusername'])) {
    $username = $_SESSION['directusername'];
    // strip the extension off the image filename
    $imagetypes = array('/\.gif$/', '/\.jpg$/', '/\.jpeg$/', '/\.png$/');
    $name = preg_replace($imagetypes, '', basename($_FILES['photo']['name'][$number]));
    // change the images names to the user name _ the photo number
    $newname = str_replace ('name', '$username_$number', $name);
    // create an image resource for the original
    switch($type) {
    case 1:
    $source = @ imagecreatefromgif($original);
    if (!$source) {
    $result = 'Cannot process GIF files. Please use JPEG or PNG.';
    break;
    case 2:
    $source = imagecreatefromjpeg($original);
    break;
    case 3:
    $source = imagecreatefrompng($original);
    break;
    default:
    $source = NULL;
    $result = 'Cannot identify file type.';
    // make sure the image resource is OK
    if (!$source) {
    $result = 'Problem uploading image, please try again or contact us for further assistance';
    else {
    // calculate the dimensions of the thumbnail
    $thumb_width = round($width * $ratio);
    $thumb_height = round($height * $ratio);
    // create an image resource for the thumbnail
    $thumb = imagecreatetruecolor($thumb_width, $thumb_height);
    // create the resized copy
    imagecopyresampled($thumb, $source, 0, 0, $x, $y, $thumb_width, $thumb_height, $width, $height);
    // save the resized copy
    switch($type) {
    case 1:
    if (function_exists('imagegif'))  {
    $success[] = imagegif($thumb, THUMBS_DIR.$newname.'.gif');
    $photoname = $newname.'.gif';
    else {
    $success[] = imagejpeg($thumb, THUMBS_DIR.$newname.'.jpg',50);
    $photoname = $newname.'.jpg';
    break;
    case 2:
    $success[] = imagejpeg($thumb, THUMBS_DIR.$newname.'.jpg', 100);
    $photoname = $newname.'.jpg';
    break;
    case 3:
    $success[] = imagepng($thumb, THUMBS_DIR.$newname.'.png');
    $photoname = $newname.'.png';
    if ($success) {
    $result[] = "Upload sucessful";
    else {
    $result[] = 'Problem uploading image, please try again or contact us for further assistance';
    // remove the image resources from memory
    imagedestroy($source);
    imagedestroy($thumb);
    ?>
    I hope i´ve supplied enough information and look forward to receiving any help or advise in this matter.

    Use double quotes here:
    $newname = str_replace ('name', '$username_$number', $name);
    Change it to this:
    $newname = str_replace ('name', "$username_$number", $name);

Maybe you are looking for