Hssain Aitkadir
Hssain Aitkadir

Reputation: 11

upload images working on localhost byt it's not working on server

this code for upload images it's working on localhost but when I upload it to the server it's put images between the php files. what is wrong please

      $my = rand(0, 66666666);
      $my .= $ImgName;
      $my1 = rand(0, 7777777);
      $my1 .= $ImgName1;
      $my2 = rand(0, 8888888);
      $my2 .= $ImgName2;
      $my3 = rand(0, 99999999);
      $my3 .= $ImgName3;
      $my4 = rand(0, 25874963);
      $my4 .= $ImgName4;

      move_uploaded_file($ImgTmp, "upload\img\\". $my);
      move_uploaded_file($ImgTmp1, "upload\img\\". $my1);
      move_uploaded_file($ImgTmp2, "upload\img\\". $my2);
      move_uploaded_file($ImgTmp3, "upload\img\\". $my3);
      move_uploaded_file($ImgTmp4, "upload\img\\". $my4);

Upvotes: 0

Views: 36

Answers (2)

iamuchejude
iamuchejude

Reputation: 66

Try replacing what you have with this:

  move_uploaded_file($ImgTmp, 'upload/img/'.$img);
  move_uploaded_file($ImgTmp1, 'upload/img/'.$img);
  move_uploaded_file($ImgTmp2, 'upload/img/'.$img);
  move_uploaded_file($ImgTmp3, 'upload/img/'.$img);
  move_uploaded_file($ImgTmp4, 'upload/img/'.$img);

Make sure your upload directory is available.

Happy coding!

Upvotes: 2

Hssain Aitkadir
Hssain Aitkadir

Reputation: 11

thank you guys I fix it using this solution

      $my = rand(0, 66666666);
      $my .= $ImgName;
      $my1 = rand(0, 7777777);
      $my1 .= $ImgName1;
      $my2 = rand(0, 8888888);
      $my2 .= $ImgName2;
      $my3 = rand(0, 99999999);
      $my3 .= $ImgName3;
      $my4 = rand(0, 25874963);
      $my4 .= $ImgName4;

       $target = "upload/img/".basename($my);
       $target1 = "upload/img/".basename($my1);
       $target2 = "upload/img/".basename($my2);
       $target3 = "upload/img/".basename($my3);
       $target4 = "upload/img/".basename($my4);

      move_uploaded_file($ImgTmp,  $target);
      move_uploaded_file($ImgTmp1, $target1);
      move_uploaded_file($ImgTmp2, $target2);
      move_uploaded_file($ImgTmp3, $target3);
      move_uploaded_file($ImgTmp4, $target4);

Upvotes: 0

Related Questions