473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

php script upload works while register global Off

22
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

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //  ************ you should change  ********************
  4. /*  The change only between the quotations */
  5.  
  6. // Name of the site
  7. $neme_sate = "";
  8.  
  9. // The upload folder
  10. $Dir = "";
  11.  
  12. //the path of the upload script, and must end with "/"
  13. $ULR = "";
  14.  
  15. //  ************ Optional  ************************
  16.  
  17. // authorization
  18. $user1 = "1" ;  //if you want to to use it by a valid username put "1"
  19.  
  20. // the name of the user
  21. $user = "test" ;
  22.  
  23. //maximun file size in kb
  24. $size_end = "200";
  25.  
  26. // specify the files
  27. $exten = array (".jpg",".JPG");
  28.  
  29.  
  30. //  ***********  style modifications ******************
  31. //page backround
  32. $body = "EDF3F3"; 
  33. // table color borders
  34. $color1 = "006F00"; 
  35. // table color head
  36. $color2 = "669999"; 
  37. // table background color
  38. $color3 = "E1ECEC";
  39. // font color head
  40. $font_color1 = "E1ECEC";
  41. // font color content
  42. $font_color2 = "000000 ";
  43.  
  44.  
  45. //*****************************************************
  46. // changing this, the uploader will not work
  47. //*****************************************************
  48. $exten1 = strrchr($file1_name ,'.');
  49. $exten2 = strrchr($file2_name ,'.');
  50. $exten3 = strrchr($file3_name ,'.');
  51. $size_round = round (($size_end * 1024) ,0);
  52. $size1 = round(($file1_size / 1024),1) ;
  53. $size2 = round(($file2_size / 1024),1) ;
  54. $size3 = round(($file3_size / 1024),1) ;
  55. $sizeall =$size1+ $size2+ $size3;
  56. $fp = fopen ("count.txt", "r");
  57. $bytes = 7;
  58. $buffer = fread($fp, $bytes);
  59. fclose ($fp);
  60. $fp2 = fopen ("count.txt", "w+");
  61. fwrite ($fp2, $buffer+1);
  62. fclose ($fp2);
  63. $Count=$buffer+1;
  64. echo "<body background=../images/bricks.gif>";
  65. echo "
  66.   <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"  height=\"100%\">
  67.     <tr><td width=\"100%\" valign=\"top\">
  68.       <p align=\"center\" style=\"margin-bottom: 25\">
  69.        <img border=\"0\" src=\"logo_med.gif\">
  70.       </td</tr>
  71.       <tr><td width=\"100%\" valign=\"\">
  72.       <p align=\"center\"><b>
  73.       ";
  74.    switch ($ar1ar)
  75.         {
  76.       default:
  77.      echo "<html>";
  78.      echo "<title>$neme_sate</title>";
  79. echo "<CENTER>
  80. <form method=\"POST\" action=\"$PHP_SELF?ar1ar=up\" enctype=\"multipart/form-data\">
  81. <div align=\"center\">
  82. <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
  83. <tr><td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  84. <p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"FFFF00\"><b>term of use</b></font></td>
  85. </tr>
  86.         <tr><td width=\"100%\" bgcolor=\"FEF9DA\">
  87.         <p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\">
  88.         <font color=\"$font_color2\"> <b>The size of the image should be smaller than :  ( $size_end ) kb</b></font>
  89.         </td></tr>
  90.          </table>
  91.          <p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\">&nbsp;</p> ";
  92.          if ($user1 == "1")
  93.          {
  94.          echo "
  95.        <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\"  bordercolor=\"$color1\" width=\"90%\">
  96.       <tr>
  97.         <td width=\"100%\" bgcolor=\"FEF9DA\" style=\"padding-right: 20\">
  98.         <p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"$font_color1\"><b>login</b></font></td>
  99.       </tr>
  100.         <tr><td width=\"100%\" bgcolor=\"$color3\">
  101.         <p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\">
  102.          <input type=text name=text1 size=50>  <font color=\"$font_color2\"><b>The username :&nbsp;</b></font>
  103.       </td></tr>
  104.        </table>
  105.           ";
  106.        }
  107.          echo "
  108.          <p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\">&nbsp;</p>
  109.          <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
  110.       <tr>
  111.         <td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  112.         <p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"FFFF00\"><b>upload images</b></font></td>
  113.       </tr>
  114.       <tr><td width=\"100%\" bgcolor=\"FEF9DA\">
  115.         <p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\">
  116.          <input type=file name=file1 size=50><br>
  117.          <input type=file name=file2 size=50><br>
  118.          <input type=file name=file3 size=50><br>
  119.       </td></tr>
  120.       <tr><td width=\"100%\" bgcolor=\"FEF9DA\">
  121.         <p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\">
  122.         <font color=\"000000\"><b>
  123.         <button name=\"submit\" type=\"submit\">upload</button>
  124.         <input type=\"reset\" value=\"reset\" name=\"B2\">
  125.         </b></font>
  126.         </td></tr></table>
  127.         </form>
  128.           ";
  129.           echo "$Count : number of vistors<br>";
  130.          break;
  131.         case "up":
  132.         echo "<title>$neme_sate</title>";
  133.         if (($user1=="1") && ($text1 <> "$user"))
  134.         {
  135.           echo  "
  136.          <div align=\"center\">
  137.          <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  138.            <tr>
  139.          <td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\">
  140.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>error</b></font></td>
  141.           </tr>
  142.           <tr><td width=\"100%\" bgcolor=\"$color3\">";
  143.           echo "<font color=\"$font_color2\"><b><br>wrong username<br><br></b></font>";
  144.           echo " </td></tr></table><br> ";
  145.          }
  146.          else{
  147.          if ($user1 == "1")
  148.        {
  149.         echo  "
  150.      <div align=\"center\">
  151.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  152.        <tr>
  153.          <td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\">
  154.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>login username</b></font></td>
  155.        </tr>
  156.      <tr><td width=\"100%\" bgcolor=\"$color3\"> ";
  157.        echo "<font color=\"$font_color2\">  welocome $text1 </font><br>";
  158.        echo " </td></tr></table><br> ";
  159.        }
  160.      echo  "
  161.     <div align=\"center\">
  162.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  163.  
  164.         <tr>
  165.          <td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  166.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild one information</b></font></td>
  167.         </tr>
  168.  
  169.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\">";
  170.  
  171.  
  172.          if ($file1_name == "")
  173.             echo "<br><font color=\"$font_color2\">you did not input any image</font><br>";
  174.  
  175.          elseif (file_exists("$Dir/$file1_name"))
  176.             echo "<br><font color=\"$font_color2\">the name of the image is already found </font><br><br>";
  177.  
  178.          elseif (!in_array( $exten1 , $exten))
  179.             echo "<br><font color=\"$font_color2\">the file extinsion is not allowed</font><br><br>";
  180.  
  181.          elseif ($file1_size > "$size_round")
  182.             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>";
  183.  
  184.          else {
  185.             @copy($file1, "$Dir/$file1_name");
  186.             echo"<font color=\"$font_color2\">The image is uploaded</font><br>";
  187.             echo"<font color=\"$font_color2\">The size of the image :  $size1 kb  </font><br>";
  188.             echo"<font color=\"$font_color2\">Image url : </font><br>";
  189.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file1_name\">$ULR$Dir/$file1_name</a><br><br>";
  190.               }
  191.         echo " </td></tr></table><br> ";
  192.        echo  "
  193.      <div align=\"center\">
  194.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\"  width=\"90%\">
  195.  
  196.        <tr>
  197.          <td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  198.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild two information</b></font></td>
  199.        </tr>
  200.  
  201.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> ";
  202.  
  203.          if ($file2_name == "")
  204.             echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
  205.  
  206.          elseif (!in_array( $exten2 , $exten))
  207.             echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
  208.  
  209.          elseif (file_exists("$Dir/$file2_name"))
  210.             echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
  211.  
  212.          elseif ($file2_size > "$size_round")
  213.             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>";
  214.  
  215.          else {
  216.             @copy($file2, "$Dir/$file2_name");
  217.             echo"<font color=\"$font_color2\">The image is uploaded<br></font>";
  218.             echo"<font color=\"$font_color2\">The size of the image :  $size2 kb <br></font>";
  219.             echo"<font color=\"$font_color2\"> Image url :</font><br>";
  220.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file2_name\">$ULR$Dir/$file2_name</a><br><br>";
  221.  
  222.                }
  223.          echo " </td></tr></table><br> ";
  224.  
  225.       echo  "
  226.      <div align=\"center\">
  227.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\"  width=\"90%\">
  228.  
  229.        <tr>
  230.          <td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  231.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild three information</b></font></td>
  232.        </tr>
  233.  
  234.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> ";
  235.  
  236.          if ($file3_name == "")
  237.             echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
  238.          elseif (!in_array( $exten3 , $exten))
  239.             echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
  240.          elseif (file_exists("$Dir/$file3_name"))
  241.             echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
  242.         elseif ($file3_size > "$size_round")
  243.             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>";
  244.           else {
  245.             @copy($file3, "$Dir/$file3_name");
  246.             echo"<font color=\"$font_color2\"> The image is uploaded <br></font>";
  247.             echo"<font color=\"$font_color2\">The size of the image : $size3 kb <br></font>";
  248.             echo"<font color=\"$font_color2\"> Image url :</font><br>";
  249.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file3_name\">$ULR$Dir/$file3_name</a><br><br>";
  250.               }echo " </td></tr></table><br> ";}
  251.  
  252.            echo"<a target=\"_self\" href=\"$PHP_SELF\">home page</a><br><br>";
  253.           echo "$Count : Number of visitors<br>";
  254.           break;}
  255.          echo "
  256.          </td></tr>
  257.                 </table>
  258. ";?>
Jun 3 '12 #1
38 2217
Dormilich
8,658 Expert Mod 8TB
user provided data (form data, URL parameters) can be found in the $_POST & $_GET superglobal arrays.
Jun 4 '12 #2
studsir
22
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
Jun 4 '12 #3
Dormilich
8,658 Expert Mod 8TB
uploaded files go into $_FILES. (you need to check this out)
Jun 4 '12 #4
studsir
22
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.
Jun 4 '12 #5
Dormilich
8,658 Expert Mod 8TB
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 ...
Jun 4 '12 #6
studsir
22
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
Jun 4 '12 #7
Dormilich
8,658 Expert Mod 8TB
if you want to know whether a file has been uploaded, check the error key.
Jun 4 '12 #8
studsir
22
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))
Jun 4 '12 #9
Dormilich
8,658 Expert Mod 8TB
elseif (!in_array( $exten1 , $exten))
and where do these variables come from?
Jun 4 '12 #10
studsir
22
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.
Jun 4 '12 #11
studsir
22
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 ,'.');
Jun 4 '12 #12
Dormilich
8,658 Expert Mod 8TB
and where does $file1_name come from?
Jun 4 '12 #13
studsir
22
I do not know
it is written like this

I will try to change it to $file1.
Jun 4 '12 #14
Dormilich
8,658 Expert Mod 8TB
if you don’t tell PHP what value to give that variable, it will not work even if you change the variable name.
Jun 4 '12 #15
studsir
22
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
Jun 4 '12 #16
Dormilich
8,658 Expert Mod 8TB
post your script, then I can make comment on the issues I see.
Jun 4 '12 #17
studsir
22
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


Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3.  
  4. //  ************ you should change  ******************** 
  5. /*  The change only between the quotations */ 
  6.  
  7. // Name of the site 
  8. $neme_sate = ""; 
  9.  
  10. // The upload folder 
  11. $Dir = ""; 
  12.  
  13. //the path of the upload script, and must end with "/" 
  14. $ULR = ""; 
  15.  
  16. //  ************ Optional  ************************ 
  17.  
  18. // authorization 
  19. $user1 = "1" ;  //if you want to to use it by a valid username put "1" 
  20.  
  21. // the name of the user 
  22. $user = "test" ; 
  23.  
  24. //maximun file size in kb 
  25. $size_end = "200"; 
  26.  
  27. // specify the files 
  28. $exten = array (".jpg",".JPG"); 
  29.  
  30.  
  31. //  ***********  style modifications ****************** 
  32. //page backround 
  33. $body = "EDF3F3";  
  34. // table color borders 
  35. $color1 = "006F00";  
  36. // table color head 
  37. $color2 = "669999";  
  38. // table background color 
  39. $color3 = "E1ECEC"; 
  40. // font color head 
  41. $font_color1 = "E1ECEC"; 
  42. // font color content 
  43. $font_color2 = "000000 "; 
  44.  
  45.  
  46. //***************************************************** 
  47. // changing this, the uploader will not work 
  48. //***************************************************** 
  49. $exten1 = strrchr($file1_name ,'.'); 
  50. $exten2 = strrchr($file2_name ,'.'); 
  51. $exten3 = strrchr($file3_name ,'.'); 
  52. $size_round = round (($size_end * 1024) ,0); 
  53. $size1 = round(($file1_size / 1024),1) ; 
  54. $size2 = round(($file2_size / 1024),1) ; 
  55. $size3 = round(($file3_size / 1024),1) ; 
  56. $sizeall =$size1+ $size2+ $size3; 
  57. $fp = fopen ("count.txt", "r"); 
  58. $bytes = 7; 
  59. $buffer = fread($fp, $bytes); 
  60. fclose ($fp); 
  61. $fp2 = fopen ("count.txt", "w+"); 
  62. fwrite ($fp2, $buffer+1); 
  63. fclose ($fp2); 
  64. $Count=$buffer+1; 
  65. echo "<body background=../images/bricks.gif>"; 
  66. echo " 
  67.   <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"  height=\"100%\">
  68.      <tr><td width=\"100%\" valign=\"top\"> 
  69.       <p align=\"center\" style=\"margin-bottom: 25\"> 
  70.        <img border=\"0\" src=\"logo_med.gif\"> 
  71.       </td</tr> 
  72.       <tr><td width=\"100%\" valign=\"\"> 
  73.       <p align=\"center\"><b> 
  74.       "; 
  75.    switch ($ar1ar) 
  76.         { 
  77.       default: 
  78.      echo "<html>"; 
  79.      echo "<title>$neme_sate</title>"; 
  80. echo "<CENTER> 
  81. <form method=\"POST\" action=\"$PHP_SELF?ar1ar=up\" enctype=\"multipart/form-data\">
  82.  <div align=\"center\"> 
  83. <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
  84.  <tr><td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  85.  <p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"FFFF00\"><b>term of use</b></font></td>
  86.  </tr> 
  87.         <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> 
  88.         <p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\"> 
  89.         <font color=\"$font_color2\"> <b>The size of the image should be smaller than :  ( $size_end ) kb</b></font>
  90.          </td></tr> 
  91.          </table> 
  92.          <p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\">&nbsp;</p> ";
  93.           if ($user1 == "1") 
  94.          { 
  95.          echo " 
  96.        <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\"  bordercolor=\"$color1\" width=\"90%\">
  97.        <tr> 
  98.         <td width=\"100%\" bgcolor=\"FEF9DA\" style=\"padding-right: 20\"> 
  99.         <p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"$font_color1\"><b>login</b></font></td>
  100.        </tr> 
  101.         <tr><td width=\"100%\" bgcolor=\"$color3\"> 
  102.         <p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\"> 
  103.          <input type=text name=text1 size=50>  <font color=\"$font_color2\"><b>The username :&nbsp;</b></font>
  104.        </td></tr> 
  105.        </table> 
  106.           "; 
  107.        } 
  108.          echo " 
  109.          <p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\">&nbsp;</p>
  110.           <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
  111.        <tr> 
  112.         <td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  113.          <p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"FFFF00\"><b>upload images</b></font></td>
  114.        </tr> 
  115.       <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> 
  116.         <p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\"> 
  117.          <input type=file name=file1 size=50><br> 
  118.          <input type=file name=file2 size=50><br> 
  119.          <input type=file name=file3 size=50><br> 
  120.       </td></tr> 
  121.       <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> 
  122.         <p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\"> 
  123.         <font color=\"000000\"><b> 
  124.         <button name=\"submit\" type=\"submit\">upload</button> 
  125.         <input type=\"reset\" value=\"reset\" name=\"B2\"> 
  126.         </b></font> 
  127.         </td></tr></table> 
  128.         </form> 
  129.           "; 
  130.           echo "$Count : number of vistors<br>"; 
  131.          break; 
  132.         case "up": 
  133.         echo "<title>$neme_sate</title>"; 
  134.         if (($user1=="1") && ($text1 <> "$user")) 
  135.         { 
  136.           echo  " 
  137.          <div align=\"center\"> 
  138.          <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  139.             <tr> 
  140.          <td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\"> 
  141.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>error</b></font></td>
  142.            </tr> 
  143.           <tr><td width=\"100%\" bgcolor=\"$color3\">"; 
  144.           echo "<font color=\"$font_color2\"><b><br>wrong username<br><br></b></font>";
  145.            echo " </td></tr></table><br> "; 
  146.          } 
  147.          else{ 
  148.          if ($user1 == "1") 
  149.        { 
  150.         echo  " 
  151.      <div align=\"center\"> 
  152.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  153.         <tr> 
  154.          <td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\"> 
  155.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>login username</b></font></td>
  156.         </tr> 
  157.      <tr><td width=\"100%\" bgcolor=\"$color3\"> "; 
  158.        echo "<font color=\"$font_color2\">  welocome $text1 </font><br>"; 
  159.        echo " </td></tr></table><br> "; 
  160.        } 
  161.      echo  " 
  162.     <div align=\"center\"> 
  163.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  164.  
  165.         <tr> 
  166.          <td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  167.           <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild one information</b></font></td>
  168.          </tr> 
  169.  
  170.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\">"; 
  171.  
  172.  
  173.          if ($file1_name == "") 
  174.             echo "<br><font color=\"$font_color2\">you did not input any image</font><br>";
  175.  
  176.          elseif (file_exists("$Dir/$file1_name")) 
  177.             echo "<br><font color=\"$font_color2\">the name of the image is already found </font><br><br>";
  178.  
  179.          elseif (!in_array( $exten1 , $exten)) 
  180.             echo "<br><font color=\"$font_color2\">the file extinsion is not allowed</font><br><br>";
  181.  
  182.          elseif ($file1_size > "$size_round") 
  183.             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>";
  184.  
  185.          else { 
  186.             @copy($file1, "$Dir/$file1_name"); 
  187.             echo"<font color=\"$font_color2\">The image is uploaded</font><br>";
  188.              echo"<font color=\"$font_color2\">The size of the image :  $size1 kb  </font><br>";
  189.              echo"<font color=\"$font_color2\">Image url : </font><br>"; 
  190.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file1_name\">$ULR$Dir/$file1_name</a><br><br>";
  191.                } 
  192.         echo " </td></tr></table><br> "; 
  193.        echo  " 
  194.      <div align=\"center\"> 
  195.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\"  width=\"90%\">
  196.  
  197.        <tr> 
  198.          <td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  199.           <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild two information</b></font></td>
  200.         </tr> 
  201.  
  202.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> "; 
  203.  
  204.          if ($file2_name == "") 
  205.             echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
  206.  
  207.          elseif (!in_array( $exten2 , $exten)) 
  208.             echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
  209.  
  210.          elseif (file_exists("$Dir/$file2_name")) 
  211.             echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
  212.  
  213.          elseif ($file2_size > "$size_round") 
  214.             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>";
  215.  
  216.          else { 
  217.             @copy($file2, "$Dir/$file2_name"); 
  218.             echo"<font color=\"$font_color2\">The image is uploaded<br></font>";
  219.              echo"<font color=\"$font_color2\">The size of the image :  $size2 kb <br></font>";
  220.              echo"<font color=\"$font_color2\"> Image url :</font><br>"; 
  221.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file2_name\">$ULR$Dir/$file2_name</a><br><br>";
  222.  
  223.                } 
  224.          echo " </td></tr></table><br> "; 
  225.  
  226.       echo  " 
  227.      <div align=\"center\"> 
  228.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\"  width=\"90%\">
  229.  
  230.        <tr> 
  231.          <td width=\"100%\" background=\"../images/gradient_1.gif\" style=\"padding-right: 20\">
  232.           <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"FFFF00\"><b>feild three information</b></font></td>
  233.         </tr> 
  234.  
  235.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> "; 
  236.  
  237.          if ($file3_name == "") 
  238.             echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
  239.           elseif (!in_array( $exten3 , $exten)) 
  240.             echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
  241.           elseif (file_exists("$Dir/$file3_name")) 
  242.             echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
  243.          elseif ($file3_size > "$size_round") 
  244.             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>";
  245.            else { 
  246.             @copy($file3, "$Dir/$file3_name"); 
  247.             echo"<font color=\"$font_color2\"> The image is uploaded <br></font>";
  248.              echo"<font color=\"$font_color2\">The size of the image : $size3 kb <br></font>";
  249.              echo"<font color=\"$font_color2\"> Image url :</font><br>"; 
  250.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file3_name\">$ULR$Dir/$file3_name</a><br><br>";
  251.                }echo " </td></tr></table><br> ";} 
  252.  
  253.            echo"<a target=\"_self\" href=\"$PHP_SELF\">home page</a><br><br>"; 
  254.           echo "$Count : Number of visitors<br>"; 
  255.           break;} 
  256.          echo " 
  257.          </td></tr> 
  258.                 </table> 
  259. ";?> 
Jun 4 '12 #18
Dormilich
8,658 Expert Mod 8TB
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.
Jun 4 '12 #19
studsir
22
$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;
Jun 4 '12 #20
Dormilich
8,658 Expert Mod 8TB
$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)
Jun 4 '12 #21
studsir
22
so only change $ar1ar
to
$_GET["ar1ar"]

or
$_GET['ar1ar']

and what about the other variables.
what is the final modification index.php page
Jun 4 '12 #22
Dormilich
8,658 Expert Mod 8TB
the other variables have to be treated accordingly.
Jun 4 '12 #23
studsir
22
ok I will try.

Thank you very much
Jun 4 '12 #24
studsir
22
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


Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  
  3.  
  4. //  ************ you should change  ******************** 
  5. /*  The change only between the quotations */ 
  6.  
  7. // Name of the site 
  8. $neme_sate = ""; 
  9.  
  10. // The upload folder 
  11. $Dir = "up"; 
  12.  
  13. //the path of the upload script, and must end with "/" 
  14. $ULR = "http://localhost/"; 
  15.  
  16. //  ************ Optional  ************************ 
  17.  
  18. // authorization 
  19. $user1 = "1" ;  //if you want to to use it by a valid username put "1" 
  20.  
  21. // the name of the user 
  22. $user = "test" ; 
  23.  
  24. //maximun file size in kb 
  25. $size_end = "200"; 
  26.  
  27. // specify the files 
  28. $exten = array (".jpg",".JPG"); 
  29.  
  30.  
  31. //  ***********  style modifications ****************** 
  32. //page backround 
  33. $body = "EDF3F3";  
  34. // table color borders 
  35. $color1 = "006F00";  
  36. // table color head 
  37. $color2 = "669999";  
  38. // table background color 
  39. $color3 = "E1ECEC"; 
  40. // font color head 
  41. $font_color1 = "E1ECEC"; 
  42. // font color content 
  43. $font_color2 = "000000 "; 
  44.  
  45.  
  46. //***************************************************** 
  47. // changing this, the uploader will not work 
  48. //***************************************************** 
  49. $text1 = $_POST['text1'];
  50. $file1_name = $_FILES['file1_name']['name'];
  51. $file2_name = $_FILES['file2_name']['name'];
  52. $file3_name = $_FILES['file3_name']['name'];
  53. $file1_size = $_FILES['file1_name']['size'];
  54. $file2_size = $_FILES['file2_name']['size'];
  55. $file3_size = $_FILES['file3_name']['size'];
  56. $exten1 = strrchr($_FILES['file1_name']['name'] ,'.');
  57. $exten2 = strrchr($_FILES['file2_name']['name'] ,'.');
  58. $exten3 = strrchr($_FILES['file3_name']['name'] ,'.');
  59. $size_round = round (($size_end * 1024) ,0);
  60. $size1 = round(($file1_size / 1024),1) ;
  61. $size2 = round(($file2_size / 1024),1) ;
  62. $size3 = round(($file3_size / 1024),1) ;
  63. $sizeall =$size1+ $size2+ $size3;
  64. $fp = fopen ("count.txt", "r");
  65. $bytes = 7;
  66. $buffer = fread($fp, $bytes);
  67. fclose ($fp);
  68. $fp2 = fopen ("count.txt", "w+");
  69. fwrite ($fp2, $buffer+1);
  70. fclose ($fp2);
  71. $Count=$buffer+1;
  72. echo "<body>"; 
  73. echo " 
  74.   <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"  height=\"100%\">
  75.       <tr><td width=\"100%\" valign=\"\"> 
  76.       <p align=\"center\"><b> 
  77.       "; 
  78.    switch ($_GET['ar1ar'])
  79.         { 
  80.       default: 
  81.      echo "<html>"; 
  82.      echo "<title>$neme_sate</title>"; 
  83. echo "<CENTER> 
  84. <form method=\"POST\" action=\"$PHP_SELF?ar1ar=up\" enctype=\"multipart/form-data\">
  85.  <div align=\"center\"> 
  86. <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
  87.  <tr><td width=\"100%\" style=\"padding-right: 20\">
  88.  <p style=\"margin-top: 0; margin-bottom: 0\"><b>term of use</b></td>
  89.  </tr> 
  90.         <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> 
  91.         <p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\"> 
  92.         <font color=\"$font_color2\"> <b>The size of the image should be smaller than :  ( $size_end ) kb</b></font>
  93.          </td></tr> 
  94.          </table> 
  95.          <p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\">&nbsp;</p> ";
  96.           if ($user1 == "1") 
  97.          { 
  98.          echo " 
  99.        <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\"  bordercolor=\"$color1\" width=\"90%\">
  100.        <tr> 
  101.         <td width=\"100%\" bgcolor=\"FEF9DA\" style=\"padding-right: 20\"> 
  102.         <p style=\"margin-top: 0; margin-bottom: 0\"><font color=\"$font_color2\"><b>login</b></font></td>
  103.        </tr> 
  104.         <tr><td width=\"100%\" bgcolor=\"$color3\"> 
  105.         <p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\"> 
  106.            <font color=\"$font_color2\"><b>The username :&nbsp;</b></font><input type=text name=text1 size=50>
  107.        </td></tr> 
  108.        </table> 
  109.           "; 
  110.        } 
  111.          echo " 
  112.          <p align=\"center\" style=\"margin-top: 2; margin-bottom: 2\">&nbsp;</p>
  113.           <table border=\"1\" cellpadding=\"\0\" cellspacing=\"0\" bordercolor=\"$color1\" width=\"90%\">
  114.        <tr> 
  115.         <td width=\"100%\" style=\"padding-right: 20\">
  116.          <p style=\"margin-top: 0; margin-bottom: 0\"><b>upload images</b></td>
  117.        </tr> 
  118.       <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> 
  119.         <p align=\"center\" style=\"margin-top: 5; margin-bottom: 5\"> 
  120.          <input type=file name=file1_name size=50><br> 
  121.          <input type=file name=file2_name size=50><br> 
  122.          <input type=file name=file3_name size=50><br> 
  123.       </td></tr> 
  124.       <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> 
  125.         <p align=\"center\" style=\"margin-top: 3; margin-bottom: 3\"> 
  126.         <font color=\"000000\"><b> 
  127.         <button name=\"submit\" type=\"submit\">upload</button> 
  128.         <input type=\"reset\" value=\"reset\" name=\"B2\"> 
  129.         </b></font> 
  130.         </td></tr></table> 
  131.         </form> 
  132.           "; 
  133.           echo "$Count : number of visits<br>"; 
  134.          break; 
  135.         case "up": 
  136.         echo "<title>$neme_sate</title>"; 
  137.         if (($user1=="1") && ($_POST['text1'] <> "$user")) 
  138.         { 
  139.           echo  " 
  140.          <div align=\"center\"> 
  141.          <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  142.             <tr> 
  143.          <td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\"> 
  144.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>error</b></font></td>
  145.            </tr> 
  146.           <tr><td width=\"100%\" bgcolor=\"$color3\">"; 
  147.           echo "<font color=\"$font_color2\"><b><br>wrong username<br><br></b></font>";
  148.            echo " </td></tr></table><br> "; 
  149.          } 
  150.          else{ 
  151.          if ($user1 == "1") 
  152.        { 
  153.         echo  " 
  154.      <div align=\"center\"> 
  155.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  156.         <tr> 
  157.          <td width=\"100%\" bgcolor=\"$color2\" style=\"padding-right: 20\"> 
  158.          <p style=\"margin-top: 3; margin-bottom: 3\"><font color=\"$font_color1\"><b>login username</b></font></td>
  159.         </tr> 
  160.      <tr><td width=\"100%\" bgcolor=\"$color3\"> "; 
  161.        echo "<font color=\"$font_color2\">  welocome $text1 </font><br>"; 
  162.        echo " </td></tr></table><br> "; 
  163.        } 
  164.      echo  " 
  165.     <div align=\"center\"> 
  166.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" width=\"90%\">
  167.  
  168.         <tr> 
  169.          <td width=\"100%\" style=\"padding-right: 20\">
  170.           <p style=\"margin-top: 3; margin-bottom: 3\"><b>feild one information</b></td>
  171.          </tr> 
  172.  
  173.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\">"; 
  174.  
  175.  
  176.          if ($file1_name == "") 
  177.             echo "<br><font color=\"$font_color2\">you did not input any image</font><br>";
  178.  
  179.          elseif (file_exists("$Dir/$file1_name")) 
  180.             echo "<br><font color=\"$font_color2\">the name of the image is already found </font><br><br>";
  181.  
  182.          elseif (!in_array( $exten1 , $exten)) 
  183.             echo "<br><font color=\"$font_color2\">the file extinsion is not allowed</font><br><br>";
  184.  
  185.          elseif ($file1_size > "$size_round") 
  186.             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>";
  187.  
  188.          else { 
  189.             @copy($file1, "$Dir/$file1_name"); 
  190.             echo"<font color=\"$font_color2\">The image is uploaded</font><br>";
  191.              echo"<font color=\"$font_color2\">The size of the image :  $size1 kb  </font><br>";
  192.              echo"<font color=\"$font_color2\">Image url : </font><br>"; 
  193.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file1_name\">$ULR$Dir/$file1_name</a><br><br>";
  194.                } 
  195.         echo " </td></tr></table><br> "; 
  196.        echo  " 
  197.      <div align=\"center\"> 
  198.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\"  width=\"90%\">
  199.  
  200.        <tr> 
  201.          <td width=\"100%\" style=\"padding-right: 20\">
  202.           <p style=\"margin-top: 3; margin-bottom: 3\"><b>feild two information</b></td>
  203.         </tr> 
  204.  
  205.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> "; 
  206.  
  207.          if ($file2_name == "") 
  208.             echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
  209.  
  210.          elseif (!in_array( $exten2 , $exten)) 
  211.             echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
  212.  
  213.          elseif (file_exists("$Dir/$file2_name")) 
  214.             echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
  215.  
  216.          elseif ($file2_size > "$size_round") 
  217.             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>";
  218.  
  219.          else { 
  220.             @copy($file2, "$Dir/$file2_name"); 
  221.             echo"<font color=\"$font_color2\">The image is uploaded<br></font>";
  222.              echo"<font color=\"$font_color2\">The size of the image :  $size2 kb <br></font>";
  223.              echo"<font color=\"$font_color2\"> Image url :</font><br>"; 
  224.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file2_name\">$ULR$Dir/$file2_name</a><br><br>";
  225.  
  226.                } 
  227.          echo " </td></tr></table><br> "; 
  228.  
  229.       echo  " 
  230.      <div align=\"center\"> 
  231.      <table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse; padding-right: 26\" bordercolor=\"$color1\" id=\"AutoNumber1\"  width=\"90%\">
  232.  
  233.        <tr> 
  234.          <td width=\"100%\" style=\"padding-right: 20\">
  235.           <p style=\"margin-top: 3; margin-bottom: 3\"><b>feild three information</b></td>
  236.         </tr> 
  237.  
  238.        <tr><td width=\"100%\" bgcolor=\"FEF9DA\"> "; 
  239.  
  240.          if ($file3_name == "") 
  241.             echo "<font color=\"$font_color2\"><br>you did not input any image<br></font>";
  242.           elseif (!in_array( $exten3 , $exten)) 
  243.             echo "<font color=\"$font_color2\"><br>the file extinsion is not allowed<br><br></font>";
  244.           elseif (file_exists("$Dir/$file3_name")) 
  245.             echo "<font color=\"$font_color2\"><br>the name of the image is already found <br><br></font>";
  246.          elseif ($file3_size > "$size_round") 
  247.             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>";
  248.            else { 
  249.             @copy($file3, "$Dir/$file3_name"); 
  250.             echo"<font color=\"$font_color2\"> The image is uploaded <br></font>";
  251.              echo"<font color=\"$font_color2\">The size of the image : $size3 kb <br></font>";
  252.              echo"<font color=\"$font_color2\"> Image url :</font><br>"; 
  253.             echo"<a target=\"_blank\" href=\"$ULR$Dir/$file3_name\">$ULR$Dir/$file3_name</a><br><br>";
  254.                }echo " </td></tr></table><br> ";} 
  255.  
  256.            echo"<a target=\"_self\" href=\"$PHP_SELF\">home page</a><br><br>"; 
  257.           echo "$Count : Number of visits<br>"; 
  258.           break;} 
  259.          echo " 
  260.          </td></tr> 
  261.                 </table> 
  262. ";?> 
Jun 4 '12 #25
studsir
22
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
Jun 4 '12 #26
Dormilich
8,658 Expert Mod 8TB
this comes from using the @ operator. otherwise copy() would certainly have complained.
Jun 4 '12 #27
studsir
22
I omitted it

and the same no errors and the image file did not uploaded to the directory
Jun 4 '12 #28
Dormilich
8,658 Expert Mod 8TB
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?).
Jun 4 '12 #29
studsir
22
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
Jun 4 '12 #30
Dormilich
8,658 Expert Mod 8TB
the Manual’s section (link see above post) even gives you an example how to save an uploaded file.
Jun 4 '12 #31
studsir
22
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");
Jun 4 '12 #32
studsir
22
wow and finally manged i changed it to

move_uploaded_file($_FILES['file1_name']['tmp_name'], "$Dir/$file1_name");

and it was saved.
Jun 4 '12 #33
Dormilich
8,658 Expert Mod 8TB
yea, sometimes reading the Manual pays off …
Jun 4 '12 #34
studsir
22
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
Jun 5 '12 #35
Dormilich
8,658 Expert Mod 8TB
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.
Jun 5 '12 #36
studsir
22
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?
Jun 5 '12 #37
Dormilich
8,658 Expert Mod 8TB
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)
Jun 5 '12 #38
studsir
22
I put this

Expand|Select|Wrap|Line Numbers
  1.         <input type=hidden name=MAX_FILE_SIZE value=200000 />
  2.         <!-- maximum size for file1_name is 200000 bytes --> 
  3.          <input type=file name=file1_name size=50><br>
  4.         <input type=hidden name=MAX_FILE_SIZE value=200000 />
  5.         <!-- maximum size for file2_name is 200000 bytes --> 
  6.          <input type=file name=file2_name size=50><br>
  7.         <input type=hidden name=MAX_FILE_SIZE value=200000 />
  8.         <!-- maximum size for file3_name is 200000 bytes --> 
  9.          <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
Jun 5 '12 #39

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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)...
4
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)
9
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....
4
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...
1
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...
3
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...
2
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...
14
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...
1
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...
9
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
1
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...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.