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);

Similar Messages

  • I am using Lightroom 5 and am hapy about it, but recently I hav encountered a problem when trying to edit an image in another program, i.e. Elements. I used the clone tool, saved the result and went back to Lightroom to open the image there. I did find a

    I am using Lightroom 5 and am hapy about it, but recently I hav encountered a problem when trying to edit an image in another program, i.e. Elements. I used the clone tool, saved the result and went back to Lightroom to open the image there. I did find a second copy, but this is identic with the one I already had in Lightroom, and I can see noe result of the clone process.

    At the moment I would say it is uncertain whether Acrobat is completely ignoring the change, or whether the changes you are making aren't affecting the ink density. I have a suggestion for a test you could make to see which is the case.
    When editing in Photoshop just add a box or mark on the image, for your tests.
    - If this box does not appear in Acrobat, you know Acrobat is not seeing the edit
    - If this box does appear in Acrobat, you know the problem is that your tool for changing ink densities is not taking effect.

  • I keep receiving this error: "the application cannot be installed due to a certificate problem" when trying to update program that use adobe AIR (vudu-to-go)

    Can anyone tell me how I can get around this error? I've tried reinstalling adobe air and reinstalling the programs but neither works.

    This issue happens when an older version of Adobe Story is already installed on a system.
    To resolve this issue you will have to first remove that version and then install the latest one.
    Now depending upon which system you are using, below are the steps:
    MAC:
    Open 'Applications' folder in Finder.
    Move 'Adobe Story' application to Trash and remove it from Trash too.
    Just to make sure that this application is not installed on a different drive, do a search for 'Adobe Story' in spotlight. If it is present on a different location, then remove it from there too.
    Now log into story.adobe.com and download the desktop application again and install it.
    WINDOWS:
    Open Controls Panel and uninstall Adobe Story application
    Now log into story.adobe.com and download the desktop application again and install it

  • I got problem when trying to contact my iphone 4 using facetime,it did ringing,but my iphone 4 did not receive that call as if nothing happen.But,when the call ended,that call appeared in the missed call list.fyi both are connected to internet.

    i got problem when trying to call my iphone 4 using facetime with my Macbook Pro 13',it did ringing,but my iphone 4 did not receive that call as if nothing happen.But,when the call ended,that call appeared in the missed call list.fyi both are connected to internet.Help!! thank you in advance

    i got problem when trying to call my iphone 4 using facetime with my Macbook Pro 13',it did ringing,but my iphone 4 did not receive that call as if nothing happen.But,when the call ended,that call appeared in the missed call list.fyi both are connected to internet.Help!! thank you in advance

  • How do i deactivate a device through icloud if the device is broken and i am unable to turn on find my iphone? Also i do not own a apple id as ive been using a family members due to problems when trying to make one?

    How do i deactivate a device through icloud if the device is broken and i am unable to turn on find my iphone? Also i do not own a apple id as ive been using a family members due to problems when trying to make one?

    Hey tyjox,
    Thanks for the question. After reviewing your post, it sounds like you need to deactivate Find My iPhone on a device that does not work. You will need to work with the family member of the account the iPhone is registered with. I would recommend that you use this article to help you resolve or isolate the issue.
    iCloud: Remove your device from Find My iPhone
    http://support.apple.com/kb/PH2702
    Remove an iOS device you no longer have
    If you no longer have the iOS device because you gave it away or sold it, you need to remotely erase it before you can remove it.
    Sign in to icloud.com/#find with your Apple ID (the one you use with iCloud).If you’re using another iCloud app, click the app’s name at the top of the iCloud.com window, then click Find My iPhone.
    Click All Devices, then select the device.
    Click Erase [device], then enter your Apple ID password. Because the device isn’t lost, don’t enter a phone number or message.If the device is offline, the remote erase begins the next time it’s online. You’ll receive an email when the device is erased.
    When the device is erased, click Remove from Account.All your content is erased and someone else can now activate the device.
    Thanks for using Apple Support Communities.
    Have a nice day,
    Mario

  • Problem when trying to print standart invoice crystal report for SAP

    Hi All, I have the following problem when trying to print a system invoice report in crystal reports for SAP
    I pass params and load the report using this code
    Private Sub DisplayThreadReportSeq()
    Dim oView As New frmViewReport
    Dim strReportPath As String = ""
    Dim strParamName As String = ""
    Try
    Dim CR As New ReportDocument
    CR.Load(oReport.CrstPath)
    ' Declare the parameter related objects.
    SetReportValues(CR)
    Dim crParameterDiscreteValue As ParameterDiscreteValue
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldLocation As ParameterFieldDefinition
    Dim crParameterValues As ParameterValues
    ' Get the report's parameters collection.
    For Each oPar As cslParam In oReport.Params
    crParameterFieldDefinitions = CR.DataDefinition.ParameterFields
    crParameterFieldLocation = crParameterFieldDefinitions.Item(oPar.ParName)
    crParameterValues = crParameterFieldLocation.CurrentValues
    crParameterDiscreteValue = New CrystalDecisions.Shared.ParameterDiscreteValue
    crParameterDiscreteValue.Value = oPar.Value
    crParameterValues.Add(crParameterDiscreteValue)
    crParameterFieldLocation.ApplyCurrentValues(crParameterValues)
    Next
    If pPrint Then
    If oReport.Printer "" Then
    CR.PrintOptions.PrinterName = oReport.Printer
    End If
    CR.PrintToPrinter(IIf(oReport.Copies = "", 1, oReport.Copies), False, 0, 0)
    SBO_Application.StatusBar.SetText("Printed Document Successfully", SAPbouiCOM.BoMessageTime.bmt_Medium, SAPbouiCOM.BoStatusBarMessageType.smt_Success)
    Else
    oView.Text = pReport
    oView.TopMost = True
    oView.Viewer.ReportSource = CR
    oView.Hide()
    oView.ShowDialog()
    End If
    Catch ex As Exception
    Util_GenErrorLog("DisplayReport", ex)
    End Try
    End Sub
    This code works fine when the report invoke to print is developed in crystal reports version for .net 2008 or .net 2005
    when trying to print a report standart getting from SAP BO 8.8.1 using this code I getting the following error:
    Error in File C:UsersecombaAppDataLocalTemp5ARInvoiceStandartSap {300B9A68-DF05-4D7B-8F3B-1670A4493BEE}.rpt:
    Error in formula .
    'Shared numberVar SectionTotalMaxHeght;
    A number, currency amount, boolean, date, time, date-time, or string is expected here.
    This report is the standart report that SAP 8.8.1 includes and works fine on SAP.
    I referenced this dlls CrystalDecisions.CrystalReports.Engine.dll, CrystalDecisions.CrystalReports.Shared, version 10.2.3600
    How I can get these dll´s version for Crystal Report 2008 for SAP Business one or How I can solve this problem
    thanks in advance,
    Ezequiel.

    Hi Ezequiel,
    You can try to search in SAP Business One Reporting & Printing forum section or post there.
    nd.Q

  • GenericServiceFactory initialization problem when trying to load Web servic

    Hi,
    I am making a Guided procedure that calls a webservice. I have created a new Destination Template and was able to load the webservice definition successfully, but when I test the callable object I created for that same webservice y get the error:
    GenericServiceFactory initialization problem when trying to load Web service model for WSDL.
    Somehow I think there is something wrong with the user authentication. The Destination template has a user and password but somehow I think the callable object test is not using this information at all.
    Can anyone help ?
    Thanks in advance

    Hi Hans,
    Have you verified if you can call any external web service calls from your J2EE engine?  Go into the SOA Management / Global settings (if you are on CE - if you're on 7.0 it's in manage WS desintations).
    Look at your proxy settings and set them like your web browser that enables external calls.  For example, in the SAP network I set my global proxy settings on my local J2EE engine to be:
    Proxy host:  proxy
    Proxy port: 8080
    Exclude list:  *.sap.corp
    Does that make sense - have you verified if your settings are correct for your company?
    Regards
    Ginger

  • On my Ipad I seem to be having a problem when trying to play YouTube videos embedded on Facebook.   When I click the links, I get a message saying: "Flash Player upgrade required."   and under it, it says, "You need to download and install the lastes vers

    On my Ipad I seem to be having a problem when trying to play YouTube videos embedded on Facebook.
    When I click the links, I get a message saying: "Flash Player upgrade required."
    and under it, it says, "You need to download and install the lastes version of Adobe Flash Player to view this content"
    and also a green button saying "Get Flash Player"
    I get this if using chrome or safari .
      I can go direct to YouTube it just works.

    The Facebook link to the video is accessing an Adobe Flash video.  Unfortunately, no iOS devices can play flash. 

  • "The Directory Service is Busy." Error Message When Trying to Rename PCs on AD 2012 R2 Domain

    As the title says, I'm trying to rename some existing PCs on a Windows 2012 R2 Active Directory domain, but I keep getting the error: The
    Directory Service is Busy.
    The command I am using is:
    netdom renamecomputer <OLD_NAME> /newname:<NEW_NAME> /ud:DOMAIN\user /pd:* /force /reboot:300
    This command works on some machines but not others. Using Powershell elicits the same response. Any troubleshooting suggestions?
    (this is cross post from Powershell here: https://social.technet.microsoft.com/Forums/windowsserver/en-US/b82cc024-4c33-47a7-bfb7-85a0a03ff357/the-directory-service-is-busy-error-message-when-trying-to-rename-pcs-on-ad-2012-r2-domain?forum=winserverpowershell)

    Hi,
    Considering that your issue isn't really PowerShell specific I'd probably try asking this question over in the Directory Services forum:
    https://social.technet.microsoft.com/Forums/en-us/home?forum=winserverDS&filter=alltypes&sort=lastpostdesc
    Perhaps someone here will have some answers for you as well, but I imagine the DS forum will be your quickest route to an answer.
    Don't retire TechNet! -
    (Don't give up yet - 13,225+ strong and growing)

  • I keep getting an "Update Failed" message when trying to update my apps using Creative Cloud.

    I keep getting an "Update Failed" message when trying to update my apps using Creative Cloud.

    [ Mac 10.9.3 / Indesign CC update fail / Premiere update fail / Adobe Media Encoder 7.2.2 update fail ]
    Adobe Media Encoder was the problem for me. There's no separate uninstaller for AME. My ID CC and Premiere couldn't be updated (for the AME7.2.2 update as the only change). MCMHMPEGVideoCodec.framework seemed to be the factor.
    I uninstalled Premiere (only), after having manually removed MCMHMPEGVideoCodec.framework from inside AME. After boot I installed it again and voilà, both (ID & Premiere) updates went trough fine. The MCMHMPEGVideoCodec.framework was on place inside AME too.

  • TS4268 I have apple ID and when trying to sign in to use FaceTime,i always get registration error.how may you help me for that guys,thanks.

    I have apple ID and when trying to sign in to use FaceTime,I always get error in registration,(This words always apper; The server encountered an error processing registration.Please try again later.)
    Can I get your Advise on what to do? Thanks

    Using FaceTime http://support.apple.com/kb/ht4319
    Troubleshooting FaceTime http://support.apple.com/kb/TS3367
    The Complete Guide to FaceTime + iMessage: Setup, Use, and Troubleshooting
    http://tinyurl.com/a7odey8
    Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268
    iOS: FaceTime is 'Unable to verify email because it is in use'
    http://support.apple.com/kb/TS3510
    Using FaceTime and iMessage behind a firewall
    http://support.apple.com/kb/HT4245
    iOS: About Messages
    http://support.apple.com/kb/HT3529
    Set up iMessage
    http://www.apple.com/ca/ios/messages/
    iOS 6 and OS X Mountain Lion: Link your phone number and Apple ID for use with FaceTime and iMessage
    http://support.apple.com/kb/HT5538
    How to Set Up & Use iMessage on iPhone, iPad, & iPod touch with iOS
    http://osxdaily.com/2011/10/18/set-up-imessage-on-iphone-ipad-ipod-touch-with-io s-5/
    Troubleshooting Messages
    http://support.apple.com/kb/TS2755
    Troubleshooting iMessage Issues: Some Useful Tips You Should Try
    http://www.igeeksblog.com/troubleshooting-imessage-issues/
    Setting Up Multiple iOS Devices for iMessage and Facetime
    http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    FaceTime and iMessage not accepting Apple ID password
    http://www.ilounge.com/index.php/articles/comments/facetime-and-imessage-not-acc epting-apple-id-password/
    Unable to use FaceTime and iMessage with my apple ID
    https://discussions.apple.com/thread/4649373?tstart=90
    FaceTime, Game Center, Messages: Troubleshooting sign in issues
    http://support.apple.com/kb/TS3970
    How to Block Someone on FaceTime
    http://www.ehow.com/how_10033185_block-someone-facetime.html
    My Facetime Doesn't Ring
    https://discussions.apple.com/message/19087457
    To send messages to non-Apple devices, check out the TextFree app https://itunes.apple.com/us/app/text-free-textfree-sms-real/id399355755?mt=8
    How to Send SMS from iPad
    http://www.iskysoft.com/apple-ipad/send-sms-from-ipad.html
    You can check the status of the FaceTime/iMessage servers at this link.
    http://www.apple.com/support/systemstatus/
     Cheers, Tom

  • I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

    I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

    I am trying to softproof an image using a CMYK .icc file. I sent an image from LR 5 to PS CC 2014, opened the Camera Raw FIlter, but the hyperlink to access workflow is not showing up in the CR dialogue box... Any ideas why this might be?

  • I am having the problem when trying to take a panorama picture.   It may only take the first frame or doesn't even start at all when I press the shutter button. even though when i  hold the phone straight up and down, so that camera is at the top

    I am having the problem when trying to take a panorama picture. 
    It may only take the first frame or doesn't even start at all when I press the shutter button.
    even though when i  hold the phone straight up and down, so that camera is at the top on the back and the home button is on the bottom on the front.
    This problem is irritating me....?

    To take panorama
    - ensure that the panorama option is on
    - press the shutter button once
    - you will see a line with an arrow
    - move around in a circle  ( I keep the camera steady and turn myself around in a circle)
    - as you do this you will see the arrow moving across the screen as it captures pictures
    - at the end of the capture, you will be able to see your panorama picture
    I hope that this helps, do report back.

  • I'm getting this problem when trying to update my iphone 3gs it says that the iphone software could not be contacted and I went on youtube got some advise to go into my hard drive to fix the error I have nothing in my host file please help me if you can

    I'm getting this problem when trying to update my iphone 3gs it says that the iphone software could not be contacted and I went on youtube got some advise to go into my hard drive to fix the error I have nothing in my host file please help me if you can this is all new to me.

    Read this: iOS 4: Updating your device to iOS 5 or later
    ... oh I think it is a 3gs or a 3
    This makes a difference. What does it say in Settings > General > About?

  • Hi There, I have a problem when trying to print either Email or from a web page.

    Hi There,
    I have a problem when trying to print contents fro either Email's or from web pages, the problem started after i opened Google earth and it down loaded Google Chrome i do not like Google chrome so i removed it from my pc via add and remove programmes since then when i try to print an email i get what looks like the computer settings for writing the email and not the text same for web pages, as anyone come across this problem before i can print any word or spreadsheet documents but problem is with email's and web pages.
    Many Thanks.

    Something changed on your system, possibly when Google Chrome installed. It could  be many things, but what it boils down to, is it needs to go back to the way it was. Either by removing whatever else might still be left from the install, or maybe by reinstalling the printer itself.
    007OHMSS
    I was a support engineer for HP.
    If the advice resolved the situation, please mark it as a solution. Thank you.

Maybe you are looking for

  • TV display connector

    I connected my MBP to Denon A/V receiver, which output 1080p to a front projector. I now use a 18 pin DVI-D single link cable. If I change to a 24 pin dual-link DVI-D cable will I get better performance? such as higher resolution or faster refresh ra

  • Authorisation variable using customer exit

    Hi, how to populate a authorisation object at runtime? is it possible to have a variable etc that can be populated a runtime? I have a object zsales_off which has different values for different users. i need to create separate roles just to have diff

  • MR21 performance slow on price update for several materials for a company c

    Hi, Can you please tell me if anyone has faced the problem of price updates through MR21 being very slow when performing the update for several materials at one go? Is there a resolution to this? Thanks in advance

  • Help Creating an Adjustable Grid?

    I have some experience in flash and actionscript, but not much beyond the classroom in a book tutorials, etc. I am working on an idea and just need a little help figuring out where to begin. I would like to create a simple 2D interactive grid.  The u

  • Created New User Account but iTunes Still Crossing Over.

    I just purchased a nano for my boyfriend and I created a new user account on my PC so the iTunes for his nano will not interfere with the iTunes for my mini. After I created his account and logged on I noticed that the icon for iTunes for my mini is