Solved

php file upload  overwrite

Posted on 2009-06-27
8
506 Views
Last Modified: 2012-05-07
hello -

i'm using some commercial php upload script that i purchased years ago.

the problem is it won't allow me to overwrite my images which i have to do for this particular application - it just creates new ones.

don't know a lot about php upload so i tried throwing an $overwrite=true variable in the code for kicks and nothing changed. here's the way the code for the variables:

// *** BEGIN Simply Upload ***
require_once("FXInc/uploadAction.inc");
$errMsg = "";
$action = true;
$noPath = true;
$rename = false;
$delete = false;
$overwrite = true;
$FX_successRedirect = "";
$FX_DirPath = "../images/ba/".$thumbs_dir."/thumbs/";
$FX_typearray = array("application","audio","image");
$FX_extarray = array();
$FX_size = "";
$FX_fields = array();
if ((isset($HTTP_POST_VARS["FX_upload"])) && ($HTTP_POST_VARS["FX_upload"] == "form1")) {
  require_once("FXInc/upload.inc");
}
// *** END Simply Upload ***
0
Comment
Question by:phillystyle123
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Expert Comment

by:szewkam
ID: 24728981
well it look like the code you have has few years ;). The $HTTP_POST_VARS variable is deprecated for long time ;). Maybe you should consider pay someone to wrote or modify your script :).
But back to the point. You have to show us a little bit more of your code, fragment you show us is too small. We can't predict problem just from definition of variables ;)
0
 

Author Comment

by:phillystyle123
ID: 24729226
thanks for taking a look at this szewkam:

this file looks relevant:

<?php
function renameIt($name,$path) {
  $re = "/\(\d+\)/";
  if (preg_match($re,$name,$matches)) {
    $num = substr($matches[0],1,strlen($matches[0])-2);
    $newName = preg_replace($re,"(".(++$num).")",$name);
  } else {
    $newName = str_replace(".","(1).",$name);
  }
  if (file_exists($path . $newName)) $newName = renameIt($newName,$path);
  return $newName;
}
 
$FX_uploadAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $FX_uploadAction .= "?" . htmlentities($HTTP_SERVER_VARS['QUERY_STRING']);
}
?>

Open in new window

0
 
LVL 5

Accepted Solution

by:
solutionDriver earned 500 total points
ID: 24730486
Hi phillystyle123,

if you want to overwrite the file everytime, you can simply make a small change to the rename function,
like this:

function renameIt($name,$path) {

  return $name; // amendment: don't rename  -- phillystyle123, [date]

  $re = "/\(\d+\)/";

  [...]
}

Make sure that the file is writable. If there are problems with overwriting the file,
you can have the old one deleted beforehand:

function renameIt($name,$path) {

  unlink($path . $newName);
  return $name; // amendment: don't rename  -- phillystyle123, [date]

  $re = "/\(\d+\)/";

  [...]
}

Best,

  sd

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 7

Expert Comment

by:szewkam
ID: 24730882
you can also find a file where function renameIt is called, and just comment line with it or remove the call :)
0
 

Author Comment

by:phillystyle123
ID: 24731931
thanks guys - solutionDriver - can you show me where your code would fit into my code?

this is what i'm guessing:
<?php
function renameIt($name,$path) {
unlink($path . $newName);
  return $name; // amendment: don't rename  -- phillystyle123, [date]
 
  $re = "/\(\d+\)/";
  $re = "/\(\d+\)/";
  if (preg_match($re,$name,$matches)) {
    $num = substr($matches[0],1,strlen($matches[0])-2);
    $newName = preg_replace($re,"(".(++$num).")",$name);
  } else {
    $newName = str_replace(".","(1).",$name);
  }
  if (file_exists($path . $newName)) $newName = renameIt($newName,$path);
 }
 
$FX_uploadAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $FX_uploadAction .= "?" . htmlentities($HTTP_SERVER_VARS['QUERY_STRING']);
}
?>

Open in new window

0
 
LVL 14

Expert Comment

by:profya
ID: 24732006
You may need to change $delete = false; to $delete = true; and to make sure that there is enough permissions for deletion. Overwrite is simply delete then create new.
0
 
LVL 5

Expert Comment

by:solutionDriver
ID: 24732098
Hello phillystyle123.

that's exactly right, you got it.

Best,

  sd
0
 

Author Closing Comment

by:phillystyle123
ID: 31597590
thanks solutionDriver!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

778 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