Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php file upload  overwrite

Posted on 2009-06-27
8
Medium Priority
?
516 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 2000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

824 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