...

View Full Version : help making 2 thing happen



webandwe
06-05-2007, 02:20 PM
Hi, I got form that let you state a folder name, on sumbit thw script creates the folder with the name you stated, the problem is I want it to upload the php file "view.php" when the folder is created, I think I set the value wrong but can get it to work

original script



Code: ( php )
<?php
#include ("mymail.php");
$folder = $_POST['folder'];
?>
<?php
mkdir("$folder", 0777);
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Mardos/title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?

while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value))
{
$filename = $value;

$add = "$folder/$filename";

//echo $_FILES[images][type][$key];
// echo "<br>";
copy($_FILES[images][tmp_name][$key], $add);
chmod("$add",0777);


}
}


?>


</body>

</html>



My first try



Code: ( php )
<?php
#include ("mymail.php");
$folder = $_POST['folder'];
?>
<?php
mkdir("$folder", 0777);
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Mardos/title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?

while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value))
{
$filename = $value;
$add= "$folder/view.php";
$add. = "$folder/$filename";
# I also tried it without the dot

//echo $_FILES[images][type][$key];
// echo "<br>";
copy($_FILES[images][tmp_name][$key], $add);
chmod("$add",0777);


}
}


?>


</body>

</html>


my second try




Code: ( php )
<?php
#include ("mymail.php");
$folder = $_POST['folder'];
?>
<?php
mkdir("$folder", 0777);
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Mardos/title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?

while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value))
{
$filename = $value;
$view= "$folder/view.php";
$add = "$folder/$filename";

//echo $_FILES[images][type][$key];
// echo "<br>";
copy($_FILES[images][tmp_name][$key], $add, $view);
chmod("$add",0777);


}
}


?>


</body>

</html>

Ahri
06-05-2007, 03:08 PM
I had to read your post at least 4 times to understand what the question was, please be more specific about your actual goals next time; "I would like to alter this script so that it not only uploads a file to a given directory, but also copies over my view.php script into that directory".

Where is this view.php file? You're not "uploading" view.php as you claim, so where on the webserver is it?

Personally I'd rewrite it like this;

if(!empty($value)) {
$add = sprintf('%s/%s', escapeshellarg($folder), escapeshellarg($value));
$view = sprintf('%s/view.php', escapeshellarg($folder));

copy($_FILES[images][tmp_name][$key], $add);
copy('/location/of/view.php', $view);

chmod($add, 0644);
chmod($view, 0755);
}

Note that I altered the chmod commands; 0644 should be fine for any uploaded file (it makes it read/write for the owner, and read-only for anyone else), and 0755 for an executable script (read/write/execute for owner, read/execute for anyone else). If this is unsatisfactory try 0775 and 0664, but 0777 is read/write/execute for anyone, which is a security hole.

I'd also move that '/location/of/view.php' to a define() somewhere in the header of your script;
define('VIEW_SCRIPT_LOCATION', '/location/of/view.php'); and then refer to the script with the constant VIEW_SCRIPT_LOCATION in my above code.

Even better, if you're using a Linux host, would be to use symbolic links instead of making loads of copies of view.php -- just link to its location instead, that way when you update view.php later you'll have updated ALL 'copies' in one go; replace the copy() of view.php with something like
symlink($view, '/location/of/view.php'); Again, this would be neater if you used the VIEW_SCRIPT_LOCATION constant.

I can't help but think that your whole architecture could do with reworking, the way you're doing it now is a bit nasty ;) You're also not checking for errors of any kind, which will no doubt bring you back later wondering why it won't work.

PS. just in case you're unaware; 755 is a decimal integer, whereas 0755 is an octal integer (the leading 0 denotes this in PHP).

I hope that helps anyway :)

webandwe
06-06-2007, 10:20 AM
Hi Man,

Sorry for my bad English, I try to explain better next time.

That script you gave me did not quite work as it should, I guess it does not work well with the previous page that runs before it.

However I managed to use your coding and got it working...

Thank you for your response and coding help!!! :thumbsup:

Regards,



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum