I have this script which is old, and I want to convert it to work under register global Off and php 5.3
I tried many things and failed , by the way I do not know much about php, so kindly If you want to help give me the the whole working script or show me exactly where to change any thing.
Here is the source of my index.php - <?php
-
-
// ************ you should change ********************
-
/* The change only between the quotations */
-
-
// Name of the site
-
$neme_sate = "";
-
-
// The upload folder
-
$Dir = "";
-
-
//the path of the upload script, and must end with "/"
-
$ULR = "";
-
-
// ************ Optional ************************
-
-
// authorization
-
$user1 = "1" ; //if you want to to use it by a valid username put "1"
-
-
// the name of the user
-
$user = "test" ;
-
-
//maximun file size in kb
-
$size_end = "200";
-
-
// specify the files
-
$exten = array (".jpg",".JPG");
-
-
-
// *********** style modifications ******************
-
//page backround
-
$body = "EDF3F3";
-
// table color borders
-
$color1 = "006F00";
-
// table color head
-
$color2 = "669999";
-
// table background color
-
$color3 = "E1ECEC";
-
// font color head
-
$font_color1 = "E1ECEC";
-
// font color content
-
$font_color2 = "000000 ";
-
-
-
//*****************************************************
-
// changing this, the uploader will not work
-
//*****************************************************
-
$exten1 = strrchr($file1_name ,'.');
-
$exten2 = strrchr($file2_name ,'.');
-
$exten3 = strrchr($file3_name ,'.');
-
$size_round = round (($size_end * 1024) ,0);
-
$size1 = round(($file1_size / 1024),1) ;
-
$size2 = round(($file2_size / 1024),1) ;
-
$size3 = round(($file3_size / 1024),1) ;
-
$sizeall =$size1+ $size2+ $size3;
-
$fp = fopen ("count.txt", "r");
-
$bytes = 7;
-
$buffer = fread($fp, $bytes);
-
fclose ($fp);
-
$fp2 = fopen ("count.txt", "w+");
-
fwrite ($fp2, $buffer+1);
-
fclose ($fp2);
-
$Count=$buffer+1;
-
echo "<body background=../images/bricks.gif>";
-
echo "
-
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"100%\">
-
<tr><td width=\"100%\" valign=\"top\">
-
<p align=\"center\" style=\"margin-bottom: 25\">
-
<img border=\"0\" src=\"logo_med.gif\">
-
</td</tr>
-
<tr><td width=\"100%\" valign=\"\">
-
<p align=\"center\"><b>
-
";
-
switch ($ar1ar)
-
{
-
default:
-
echo "<html>";
-
echo "<title>$neme_sate</title>";
-
echo "<CENTER>
-
<form method=\"POST\" action=\"$PHP_SELF?ar1ar=up\" enctype=\"multipart/form-data\">
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr><td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"FFFF00\"><b>term of use</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\">
-
<font color=\"$font_color2\"> <b>The size of the image should be smaller than : ( $size_end ) kb</b></font>
-
</td></tr>
-
</table>
-
<p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\"> </p> ";
-
if ($user1 == "1")
-
{
-
echo "
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"FEF9DA\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"$font_color1\"><b>login</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\">
-
<p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\">
-
<input type=text name=text1 size=50> <font color=\"$font_color2\"><b>The username : </b></font>
-
</td></tr>
-
</table>
-
";
-
}
-
echo "
-
<p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\"> </p>
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"FFFF00\"><b>upload images</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\">
-
<input type=file name=file1 size=50><br>
-
<input type=file name=file2 size=50><br>
-
<input type=file name=file3 size=50><br>
-
</td></tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\">
-
<font color=\"000000\"><b>
-
<button name=\"submit\" type=\"submit\">upload</button>
-
<input type=\"reset\" value=\"reset\" name=\"B2\">
-
</b></font>
-
</td></tr></table>
-
</form>
-
";
-
echo "$Count : number of vistors<br>";
-
break;
-
case "up":
-
echo "<title>$neme_sate</title>";
-
if (($user1=="1") && ($text1 <> "$user"))
-
{
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>error</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\">";
-
echo "<font color=\"$font_color2\"><b><br>wrong username<br><br></b></font>";
-
echo " </td></tr></table><br> ";
-
}
-
else{
-
if ($user1 == "1")
-
{
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>login username</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\"> ";
-
echo "<font color=\"$font_color2\"> welocome $text1 </font><br>";
-
echo " </td></tr></table><br> ";
-
}
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild one information</b></font></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">";
-
-
-
if ($file1_name == "")
-
echo "<br><font color=\"$font_color2\">you did not input any image</font><br>";
-
-
elseif (file_exists("$Dir/$file1_name"))
-
echo "<br><font color=\"$font_color2\">the name of the image is already found </font><br><br>";
-
-
elseif (!in_array( $exten1 , $exten))
-
echo "<br><font color=\"$font_color2\">the file extinsion is not allowed</font><br><br>";
-
-
elseif ($file1_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size1 and the maximun file size is $size_end kb</font><br><br>";
-
-
else {
-
@copy($file1, "$Dir/$file1_name");
-
echo"<font color=\"$font_color2\">The image is uploaded</font><br>";
-
echo"<font color=\"$font_color2\">The size of the image : $size1 kb </font><br>";
-
echo"<font color=\"$font_color2\">Image url : </font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file1_name\">$ULR$Dir/$file1_name</a><br><br>";
-
}
-
echo " </td></tr></table><br> ";
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild two information</b></font></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\"> ";
-
-
if ($file2_name == "")
-
echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
-
-
elseif (!in_array( $exten2 , $exten))
-
echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
-
-
elseif (file_exists("$Dir/$file2_name"))
-
echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
-
-
elseif ($file2_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size2 and the maximun file size is $size_end kb</font><br><br>";
-
-
else {
-
@copy($file2, "$Dir/$file2_name");
-
echo"<font color=\"$font_color2\">The image is uploaded<br></font>";
-
echo"<font color=\"$font_color2\">The size of the image : $size2 kb <br></font>";
-
echo"<font color=\"$font_color2\"> Image url :</font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file2_name\">$ULR$Dir/$file2_name</a><br><br>";
-
-
}
-
echo " </td></tr></table><br> ";
-
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild three information</b></font></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\"> ";
-
-
if ($file3_name == "")
-
echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
-
elseif (!in_array( $exten3 , $exten))
-
echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
-
elseif (file_exists("$Dir/$file3_name"))
-
echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
-
elseif ($file3_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size3 and the maximun file size is $size_end kb</font><br><br>";
-
else {
-
@copy($file3, "$Dir/$file3_name");
-
echo"<font color=\"$font_color2\"> The image is uploaded <br></font>";
-
echo"<font color=\"$font_color2\">The size of the image : $size3 kb <br></font>";
-
echo"<font color=\"$font_color2\"> Image url :</font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file3_name\">$ULR$Dir/$file3_name</a><br><br>";
-
}echo " </td></tr></table><br> ";}
-
-
echo"<a target=\"_self\" href=\"$PHP_SELF\">home page</a><br><br>";
-
echo "$Count : Number of visitors<br>";
-
break;}
-
echo "
-
</td></tr>
-
</table>
-
";?>
38 2217
user provided data (form data, URL parameters) can be found in the $_POST & $_GET superglobal arrays.
Thank you very much, I have many prefix $, so where to put $_POST and $_GET
I managed the username to work
if (($user1=="1") && ($_POST['text1'] <> "$user"))
but the files did not mange to be uploaded yet
uploaded files go into $_FILES. (you need to check this out)
I do not konw where the lines of the uploaded files, but I changed this line
if ($file1_name == "")
to
if ($_FILES['file1_name'] == "")
but it give the error messege which is:
you did not input any image
but if I changed this line
@copy($file1, "$Dir/$file1_name");
to
@copy($_FILES['file1'], "$Dir/$file1_name");
It give me everything is ok and the uploaed informations about the name of the file and the size and the url, but the file it self is not uploaded and it is not in the uploded folder.
did you really read the file upload section? what you have there is not supposed to work at all.
PS. adding an @ before anything will suppress errors ...
ok
I read it and changed this line
if ($file1_name == "")
to
if ($_FILES['file1']['name'] == "")
it uploads the file in php 4, but not in php 5.3
while register global Off
any suggestions
if you want to know whether a file has been uploaded, check the error key.
Also I changed this
elseif ($file1_size > "$size_round")
to
elseif ($_FILES['file1']['size'] > "$size_round")
it uploads the file in php 4, but not in php 5.3
while register global Off
any suggestions
*******
I think this line remains, which I cannot know how to convert it
elseif (!in_array( $exten1 , $exten))
elseif (!in_array( $exten1 , $exten))
and where do these variables come from?
sorry about my php version
I tested it in my personal server which has php 5.1.2
it worked.
but my site's server which has 5.3.3
it did not work.
in my personal server php error logs, no errors, but in my online server I cannot know where the php error logs are located.
these
elseif (!in_array( $exten1 , $exten))
comes from the file type array in the first lines above:
// specify the files
$exten = array (".jpg",".JPG");
and other lines below it
$exten1 = strrchr($file1_name ,'.');
and where does $file1_name come from?
I do not know
it is written like this
I will try to change it to $file1.
if you don’t tell PHP what value to give that variable, it will not work even if you change the variable name.
Mr. Dormilich , I am very appreciated your help, but I really not enough aware about php language.
all my script is one file which is inside the cod tags.
there ara not much variables, so please look again and give me the correct page.
Thank you very much
post your script, then I can make comment on the issues I see.
my upload script under a folder called upload
inside that directory there is a file named index.php
and a file named count.txt, and a folder called up
now when I use the http://www.domain.com/upload/index.php
I brows the iamge and when upload the url will be http://www.domain.com/upload/up/image.jpg
and the index.php has three input cells which I can manage to select three files and uploaded them at once.
and the count.txt, only has the number of the visits and increase every page visit.
here again the index.php as it is ( the original ) that works as register gloabl On, and not while it is Off - <?php
-
-
-
// ************ you should change ********************
-
/* The change only between the quotations */
-
-
// Name of the site
-
$neme_sate = "";
-
-
// The upload folder
-
$Dir = "";
-
-
//the path of the upload script, and must end with "/"
-
$ULR = "";
-
-
// ************ Optional ************************
-
-
// authorization
-
$user1 = "1" ; //if you want to to use it by a valid username put "1"
-
-
// the name of the user
-
$user = "test" ;
-
-
//maximun file size in kb
-
$size_end = "200";
-
-
// specify the files
-
$exten = array (".jpg",".JPG");
-
-
-
// *********** style modifications ******************
-
//page backround
-
$body = "EDF3F3";
-
// table color borders
-
$color1 = "006F00";
-
// table color head
-
$color2 = "669999";
-
// table background color
-
$color3 = "E1ECEC";
-
// font color head
-
$font_color1 = "E1ECEC";
-
// font color content
-
$font_color2 = "000000 ";
-
-
-
//*****************************************************
-
// changing this, the uploader will not work
-
//*****************************************************
-
$exten1 = strrchr($file1_name ,'.');
-
$exten2 = strrchr($file2_name ,'.');
-
$exten3 = strrchr($file3_name ,'.');
-
$size_round = round (($size_end * 1024) ,0);
-
$size1 = round(($file1_size / 1024),1) ;
-
$size2 = round(($file2_size / 1024),1) ;
-
$size3 = round(($file3_size / 1024),1) ;
-
$sizeall =$size1+ $size2+ $size3;
-
$fp = fopen ("count.txt", "r");
-
$bytes = 7;
-
$buffer = fread($fp, $bytes);
-
fclose ($fp);
-
$fp2 = fopen ("count.txt", "w+");
-
fwrite ($fp2, $buffer+1);
-
fclose ($fp2);
-
$Count=$buffer+1;
-
echo "<body background=../images/bricks.gif>";
-
echo "
-
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"100%\">
-
<tr><td width=\"100%\" valign=\"top\">
-
<p align=\"center\" style=\"margin-bottom: 25\">
-
<img border=\"0\" src=\"logo_med.gif\">
-
</td</tr>
-
<tr><td width=\"100%\" valign=\"\">
-
<p align=\"center\"><b>
-
";
-
switch ($ar1ar)
-
{
-
default:
-
echo "<html>";
-
echo "<title>$neme_sate</title>";
-
echo "<CENTER>
-
<form method=\"POST\" action=\"$PHP_SELF?ar1ar=up\" enctype=\"multipart/form-data\">
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr><td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"FFFF00\"><b>term of use</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\">
-
<font color=\"$font_color2\"> <b>The size of the image should be smaller than : ( $size_end ) kb</b></font>
-
</td></tr>
-
</table>
-
<p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\"> </p> ";
-
if ($user1 == "1")
-
{
-
echo "
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"FEF9DA\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"$font_color1\"><b>login</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\">
-
<p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\">
-
<input type=text name=text1 size=50> <font color=\"$font_color2\"><b>The username : </b></font>
-
</td></tr>
-
</table>
-
";
-
}
-
echo "
-
<p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\"> </p>
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"FFFF00\"><b>upload images</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\">
-
<input type=file name=file1 size=50><br>
-
<input type=file name=file2 size=50><br>
-
<input type=file name=file3 size=50><br>
-
</td></tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\">
-
<font color=\"000000\"><b>
-
<button name=\"submit\" type=\"submit\">upload</button>
-
<input type=\"reset\" value=\"reset\" name=\"B2\">
-
</b></font>
-
</td></tr></table>
-
</form>
-
";
-
echo "$Count : number of vistors<br>";
-
break;
-
case "up":
-
echo "<title>$neme_sate</title>";
-
if (($user1=="1") && ($text1 <> "$user"))
-
{
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>error</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\">";
-
echo "<font color=\"$font_color2\"><b><br>wrong username<br><br></b></font>";
-
echo " </td></tr></table><br> ";
-
}
-
else{
-
if ($user1 == "1")
-
{
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>login username</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\"> ";
-
echo "<font color=\"$font_color2\"> welocome $text1 </font><br>";
-
echo " </td></tr></table><br> ";
-
}
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild one information</b></font></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">";
-
-
-
if ($file1_name == "")
-
echo "<br><font color=\"$font_color2\">you did not input any image</font><br>";
-
-
elseif (file_exists("$Dir/$file1_name"))
-
echo "<br><font color=\"$font_color2\">the name of the image is already found </font><br><br>";
-
-
elseif (!in_array( $exten1 , $exten))
-
echo "<br><font color=\"$font_color2\">the file extinsion is not allowed</font><br><br>";
-
-
elseif ($file1_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size1 and the maximun file size is $size_end kb</font><br><br>";
-
-
else {
-
@copy($file1, "$Dir/$file1_name");
-
echo"<font color=\"$font_color2\">The image is uploaded</font><br>";
-
echo"<font color=\"$font_color2\">The size of the image : $size1 kb </font><br>";
-
echo"<font color=\"$font_color2\">Image url : </font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file1_name\">$ULR$Dir/$file1_name</a><br><br>";
-
}
-
echo " </td></tr></table><br> ";
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild two information</b></font></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\"> ";
-
-
if ($file2_name == "")
-
echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
-
-
elseif (!in_array( $exten2 , $exten))
-
echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
-
-
elseif (file_exists("$Dir/$file2_name"))
-
echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
-
-
elseif ($file2_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size2 and the maximun file size is $size_end kb</font><br><br>";
-
-
else {
-
@copy($file2, "$Dir/$file2_name");
-
echo"<font color=\"$font_color2\">The image is uploaded<br></font>";
-
echo"<font color=\"$font_color2\">The size of the image : $size2 kb <br></font>";
-
echo"<font color=\"$font_color2\"> Image url :</font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file2_name\">$ULR$Dir/$file2_name</a><br><br>";
-
-
}
-
echo " </td></tr></table><br> ";
-
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild three information</b></font></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\"> ";
-
-
if ($file3_name == "")
-
echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
-
elseif (!in_array( $exten3 , $exten))
-
echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
-
elseif (file_exists("$Dir/$file3_name"))
-
echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
-
elseif ($file3_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size3 and the maximun file size is $size_end kb</font><br><br>";
-
else {
-
@copy($file3, "$Dir/$file3_name");
-
echo"<font color=\"$font_color2\"> The image is uploaded <br></font>";
-
echo"<font color=\"$font_color2\">The size of the image : $size3 kb <br></font>";
-
echo"<font color=\"$font_color2\"> Image url :</font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file3_name\">$ULR$Dir/$file3_name</a><br><br>";
-
}echo " </td></tr></table><br> ";}
-
-
echo"<a target=\"_self\" href=\"$PHP_SELF\">home page</a><br><br>";
-
echo "$Count : Number of visitors<br>";
-
break;}
-
echo "
-
</td></tr>
-
</table>
-
";?>
yupp, that code won’t work with register_globals off. lines #49 - #51 & #53 - #55 all contain undefined variables. I can only guess what they mean, but I think you should find the info in the $_FILES superglobal.
further undefined variables (or I didn’t find them):
- $ar1ar
- $text1
- $size_round
and again, the Manual has a section about uploading multiple files.
$ar1ar
you can find it here
<form method=\"POST\" action=\"$PHP_SELF?ar1ar=up\" enctype=\"multipart/form-data\">
And when the upload finish another page will come wih results and in the address url will look like this http://localhost/upload/index.php?ar1ar=up
$text1
it is for login information , if you cant a specific username to access the uploader and when you put "1"
a new cell appear in index.php so as tp put the username which you epecify, and they are in these lines:
// authorization
$user1 = "1" ; //if you want to to use it by a valid username put "1"
// the name of the user
$user = "test" ;
if you did not put "1" the cell of the username login will not appeare
so $text1
is the input text you will input while the $user1= "1"
so the script will match the $text1 with the $user, if they are the same will continue if not error message :
wrong username
$size_round
I do not know, but you can see it here:
$size_round = round (($size_end * 1024) ,0);
$size1 = round(($file1_size / 1024),1) ;
$size2 = round(($file2_size / 1024),1) ;
$size3 = round(($file3_size / 1024),1) ;
$sizeall =$size1+ $size2+ $size3;
$ar1ar
you can find it here
<form method=\"POST\" action=\"$PHP_SELF?ar1ar=up\" enctype=\"multipart/form-data\">
And when the upload finish another page will come wih results and in the address url will look like this http://localhost/upload/index.php?ar1ar=up
exactly. but it only works with register_globals on. since PHP 4, URL parameters are put into the $_GET superglobal, hence $ar1ar = $_GET["ar1ar"]; (at the very least)
so only change $ar1ar
to
$_GET["ar1ar"]
or
$_GET['ar1ar']
and what about the other variables.
what is the final modification index.php page
the other variables have to be treated accordingly.
ok I will try.
Thank you very much
After big efforts I finally converted it without any errors. except the files are not uploaded in the Up directory
but the reslut page give everything is ok.
You can try it , here is my final index.php - <?php
-
-
-
// ************ you should change ********************
-
/* The change only between the quotations */
-
-
// Name of the site
-
$neme_sate = "";
-
-
// The upload folder
-
$Dir = "up";
-
-
//the path of the upload script, and must end with "/"
-
$ULR = "http://localhost/";
-
-
// ************ Optional ************************
-
-
// authorization
-
$user1 = "1" ; //if you want to to use it by a valid username put "1"
-
-
// the name of the user
-
$user = "test" ;
-
-
//maximun file size in kb
-
$size_end = "200";
-
-
// specify the files
-
$exten = array (".jpg",".JPG");
-
-
-
// *********** style modifications ******************
-
//page backround
-
$body = "EDF3F3";
-
// table color borders
-
$color1 = "006F00";
-
// table color head
-
$color2 = "669999";
-
// table background color
-
$color3 = "E1ECEC";
-
// font color head
-
$font_color1 = "E1ECEC";
-
// font color content
-
$font_color2 = "000000 ";
-
-
-
//*****************************************************
-
// changing this, the uploader will not work
-
//*****************************************************
-
$text1 = $_POST['text1'];
-
$file1_name = $_FILES['file1_name']['name'];
-
$file2_name = $_FILES['file2_name']['name'];
-
$file3_name = $_FILES['file3_name']['name'];
-
$file1_size = $_FILES['file1_name']['size'];
-
$file2_size = $_FILES['file2_name']['size'];
-
$file3_size = $_FILES['file3_name']['size'];
-
$exten1 = strrchr($_FILES['file1_name']['name'] ,'.');
-
$exten2 = strrchr($_FILES['file2_name']['name'] ,'.');
-
$exten3 = strrchr($_FILES['file3_name']['name'] ,'.');
-
$size_round = round (($size_end * 1024) ,0);
-
$size1 = round(($file1_size / 1024),1) ;
-
$size2 = round(($file2_size / 1024),1) ;
-
$size3 = round(($file3_size / 1024),1) ;
-
$sizeall =$size1+ $size2+ $size3;
-
$fp = fopen ("count.txt", "r");
-
$bytes = 7;
-
$buffer = fread($fp, $bytes);
-
fclose ($fp);
-
$fp2 = fopen ("count.txt", "w+");
-
fwrite ($fp2, $buffer+1);
-
fclose ($fp2);
-
$Count=$buffer+1;
-
echo "<body>";
-
echo "
-
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"100%\">
-
<tr><td width=\"100%\" valign=\"\">
-
<p align=\"center\"><b>
-
";
-
switch ($_GET['ar1ar'])
-
{
-
default:
-
echo "<html>";
-
echo "<title>$neme_sate</title>";
-
echo "<CENTER>
-
<form method=\"POST\" action=\"$PHP_SELF?ar1ar=up\" enctype=\"multipart/form-data\">
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr><td width=\"100%\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><b>term of use</b></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\">
-
<font color=\"$font_color2\"> <b>The size of the image should be smaller than : ( $size_end ) kb</b></font>
-
</td></tr>
-
</table>
-
<p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\"> </p> ";
-
if ($user1 == "1")
-
{
-
echo "
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"FEF9DA\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"$font_color2\"><b>login</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\">
-
<p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\">
-
<font color=\"$font_color2\"><b>The username : </b></font><input type=text name=text1 size=50>
-
</td></tr>
-
</table>
-
";
-
}
-
echo "
-
<p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\"> </p>
-
<table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 0; margin-bottom: 0\"><b>upload images</b></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\">
-
<input type=file name=file1_name size=50><br>
-
<input type=file name=file2_name size=50><br>
-
<input type=file name=file3_name size=50><br>
-
</td></tr>
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">
-
<p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\">
-
<font color=\"000000\"><b>
-
<button name=\"submit\" type=\"submit\">upload</button>
-
<input type=\"reset\" value=\"reset\" name=\"B2\">
-
</b></font>
-
</td></tr></table>
-
</form>
-
";
-
echo "$Count : number of visits<br>";
-
break;
-
case "up":
-
echo "<title>$neme_sate</title>";
-
if (($user1=="1") && ($_POST['text1'] <> "$user"))
-
{
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>error</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\">";
-
echo "<font color=\"$font_color2\"><b><br>wrong username<br><br></b></font>";
-
echo " </td></tr></table><br> ";
-
}
-
else{
-
if ($user1 == "1")
-
{
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
<tr>
-
<td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>login username</b></font></td>
-
</tr>
-
<tr><td width=\"100%\" bgcolor=\"$color3\"> ";
-
echo "<font color=\"$font_color2\"> welocome $text1 </font><br>";
-
echo " </td></tr></table><br> ";
-
}
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><b>feild one information</b></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\">";
-
-
-
if ($file1_name == "")
-
echo "<br><font color=\"$font_color2\">you did not input any image</font><br>";
-
-
elseif (file_exists("$Dir/$file1_name"))
-
echo "<br><font color=\"$font_color2\">the name of the image is already found </font><br><br>";
-
-
elseif (!in_array( $exten1 , $exten))
-
echo "<br><font color=\"$font_color2\">the file extinsion is not allowed</font><br><br>";
-
-
elseif ($file1_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size1 and the maximun file size is $size_end kb</font><br><br>";
-
-
else {
-
@copy($file1, "$Dir/$file1_name");
-
echo"<font color=\"$font_color2\">The image is uploaded</font><br>";
-
echo"<font color=\"$font_color2\">The size of the image : $size1 kb </font><br>";
-
echo"<font color=\"$font_color2\">Image url : </font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file1_name\">$ULR$Dir/$file1_name</a><br><br>";
-
}
-
echo " </td></tr></table><br> ";
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><b>feild two information</b></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\"> ";
-
-
if ($file2_name == "")
-
echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
-
-
elseif (!in_array( $exten2 , $exten))
-
echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
-
-
elseif (file_exists("$Dir/$file2_name"))
-
echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
-
-
elseif ($file2_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size2 and the maximun file size is $size_end kb</font><br><br>";
-
-
else {
-
@copy($file2, "$Dir/$file2_name");
-
echo"<font color=\"$font_color2\">The image is uploaded<br></font>";
-
echo"<font color=\"$font_color2\">The size of the image : $size2 kb <br></font>";
-
echo"<font color=\"$font_color2\"> Image url :</font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file2_name\">$ULR$Dir/$file2_name</a><br><br>";
-
-
}
-
echo " </td></tr></table><br> ";
-
-
echo "
-
<div align=\"center\">
-
<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\" width=\"90%\">
-
-
<tr>
-
<td width=\"100%\" style=\"padding-right: 20\">
-
<p style=\"margin-top: 3; margin-bottom: 3\"><b>feild three information</b></td>
-
</tr>
-
-
<tr><td width=\"100%\" bgcolor=\"FEF9DA\"> ";
-
-
if ($file3_name == "")
-
echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
-
elseif (!in_array( $exten3 , $exten))
-
echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
-
elseif (file_exists("$Dir/$file3_name"))
-
echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
-
elseif ($file3_size > "$size_round")
-
echo "<br><font color=\"$font_color2\">The size of the image is more than allowed<br>The size of the image is $size3 and the maximun file size is $size_end kb</font><br><br>";
-
else {
-
@copy($file3, "$Dir/$file3_name");
-
echo"<font color=\"$font_color2\"> The image is uploaded <br></font>";
-
echo"<font color=\"$font_color2\">The size of the image : $size3 kb <br></font>";
-
echo"<font color=\"$font_color2\"> Image url :</font><br>";
-
echo"<a target=\"_blank\" href=\"$ULR$Dir/$file3_name\">$ULR$Dir/$file3_name</a><br><br>";
-
}echo " </td></tr></table><br> ";}
-
-
echo"<a target=\"_self\" href=\"$PHP_SELF\">home page</a><br><br>";
-
echo "$Count : Number of visits<br>";
-
break;}
-
echo "
-
</td></tr>
-
</table>
-
";?>
by the way,
if the same name file in the up directory , the script will give me error that :
the name of the image is already found
which means that the variables are right, but when I delete the file and tryagain, the script gives that the image is uploaded, but there is no image file in the up directory
this comes from using the @ operator. otherwise copy() would certainly have complained.
I omitted it
and the same no errors and the image file did not uploaded to the directory
tbh, I see nothing where you save the uploaded files. you only have a call to copy() with an invalid argument (or did you define $file1 anywhere?).
I changed the $file1
to
Sfile1_name
and omitted the @
and the php error log gives that
copy(book.jpg): failed to open stream: No such file or directory in C:\apache2triad\htdocs\upload\index1.php
book.jpg is the image name
yes the script cannot save the uploaded files
the Manual’s section (link see above post) even gives you an example how to save an uploaded file.
really I read much and I could not save files.
I managed to solve this problem
copy(): failed to open stream: No such file or directory
by changing this line
@copy($file1_name, "$Dir/$file1_name");
to
move_uploaded_file($file1_name, "$Dir/$file1_name");
wow and finally manged i changed it to
move_uploaded_file($_FILES['file1_name']['tmp_name'], "$Dir/$file1_name");
and it was saved.
yea, sometimes reading the Manual pays off …
Dormilich
I have a littel problem.
my previouse script was very fast, if I try to upload not allowed extension or an image more than the limited size, quickly the result page tell that is wrong.
but this modification script act like it uploads the file whatever the extension or the size then after finish it sees if its extension is allowed or if its size withing the max size, if it is ok then it saves it , if it is not it tells me why not uploaded.
so why this new one upload the file then check it, it should check it then upload and save
PHP can’t check something it doesn’t know, hence the upload. but at least the file extension can be checked with JavaScript.
note before you undo everything: register_globals is a security thread, I could use any user I like by just passing user=admin (and the likes) to the form’s URL.
I see,
what about the size check, is their any way to check before upload, because that is the main problem of the slowness, as If some one want to upload a file that he do not know exceeds the size of the allowed limit, he will wait long time untill the script tells him that it is not allowed.
and according to your note, you adives me to keep the new script as the register global Off is more secure?
and according to your note, you adives me to keep the new script as the register global Off is more secure?
not just me. register_globals is not removed (!) from PHP 5.4 for no reason.
what about the size check, is their any way to check before upload, because that is the main problem of the slowness,
the slowness stems from the time it takes to upload the file, not the script itself. IIRC you can set a hidden field to the max size (but that was mentioned in the link I gave you)
I put this - <input type=hidden name=MAX_FILE_SIZE value=200000 />
-
<!-- maximum size for file1_name is 200000 bytes -->
-
<input type=file name=file1_name size=50><br>
-
<input type=hidden name=MAX_FILE_SIZE value=200000 />
-
<!-- maximum size for file2_name is 200000 bytes -->
-
<input type=file name=file2_name size=50><br>
-
<input type=hidden name=MAX_FILE_SIZE value=200000 />
-
<!-- maximum size for file3_name is 200000 bytes -->
-
<input type=file name=file3_name size=50><br>
This is what happened:
the result page comes, the file was uploaded and the size is zero , but it is not saved to the directory
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John F Dutcher |
last post by:
Having 'cloned' an existing python script that imports 'string' and
uses "string.rstrip()" without incident...
I am at a loss to explain why the new 'cloned' script (brief sample
below)...
|
by: Scott Baxter |
last post by:
Hello,
I got the following scripts to upload files to my directories
I call insert.htm
Browse for a file, then click 'submit'
It works for small files, and for a small .mdb (access file)
|
by: Arthur Jacobs |
last post by:
Good Day,
I can upload a file as long as it is empty (thanks Hendri Kurniawan).
I do not know where to look.
Can someone help me understand what I need to do to upload a small image....
|
by: BillL |
last post by:
Any help would be appreciated.
The following script works fine in FF, but not in IE6. Please advise.
----------------------------------------------
// <script type="text/javascript">
//the...
|
by: mahsina |
last post by:
I have a scrip that works in XP SP2 but not in XP SP1
--------------------------------------------------------------------------------
I have the following scrip that works in XP SP2 but not in...
|
by: macca |
last post by:
Hi people!
I'm having a problem with a file upload script that I'm writing. It
works with Firefox but not Internet explorer.
When the form is submitted(to it's self) it check for a file upload...
|
by: dmorand |
last post by:
I'm trying to get this function to work in IE, it works fine in Firefox. When I click the below link I get an error in IE.
Line:1
Char:1
Error: Object expected
Code:0
<li><a...
|
by: BigZero |
last post by:
Hello,
can nay body tell me how upload works?
"well the code that i m using works fine with me i mean that the file
uploadin is working but i m unable to find how it internal it works"?
when...
|
by: gdicks |
last post by:
I am trying to write a scriupt to serve ad slot for each region. URL's are generated dynamically. OK, so I have the following code to display the ad (Google Ad Manager)
<script...
|
by: gdicks |
last post by:
I am trying to write a scriupt to serve ad slot for each region. URL's are generated dynamically. OK, so I have the following code to display the ad (Google Ad Manager)
<script...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |