Solved

Uploading files

Posted on 2001-06-05
8
258 Views
Last Modified: 2006-11-17
Hello, Experts.

How i can upload image from browser to server, trought PHP?
I will be very glad for your answers. I am using php 4.x.

Thank you.

--
sandis
0
Comment
Question by:sviksna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 8

Expert Comment

by:us111
ID: 6156118
0
 
LVL 1

Expert Comment

by:fajr_n
ID: 6158534
0
 
LVL 1

Author Comment

by:sviksna
ID: 6159576
eeeh, isn't there any simply code for uploading a file?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

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

 
LVL 1

Expert Comment

by:rick2001
ID: 6159615
How about this for uploading a file into d:\data on a win32 system?


<html>
<head>
<title>Upload a File</title>
</head>
<body>
<h1>Upload a File</h1>
<form enctype="multipart/form-data" method="post" action="do_upload.php">
<p><strong>File to Upload:</strong><br>
<input type="file" name="img1" size="30"></p>
<P><input type="submit" name="submit" value="Upload File"></p>
</form>
</body>
</html>

<?
if (is_uploaded_file($img1))
{
        copy($img1, "d:\\data\\".basename($img1_name))
        or die("Couldn't copy the file!");
        print "File uploaded.";
}
else
{
        die("No input file specified");
}
?>
0
 
LVL 8

Expert Comment

by:us111
ID: 6159636
0
 

Expert Comment

by:jbkerra
ID: 6166153
<?
if(isset($submit)){

if ($upme_name != "") {

if(!(copy("$upme", "/your/dir/for/uploads/$upme_name")))
  print(error."bad");      
         
} else {

    die("No input file!");

}
print("Thanks for the $upme_name file!");    
}

?>
<HTML>
<HEAD>
<TITLE>Uploads</TITLE>
</HEAD>
<BODY>

<FORM METHOD="post" ACTION='<? print("$PHP_SELF?"); ?>' ENCTYPE="multipart/form-data" > 
File <INPUT TYPE="file" NAME="upme" SIZE="30"><br>
<INPUT TYPE="submit" NAME="submit" VALUE="Send">
</FORM>

</BODY>
</HTML>
0
 
LVL 1

Accepted Solution

by:
anupkarade earned 20 total points
ID: 6230231
Just Copy paste this code make the relevant changes as instructed in the commented portion and you have
the answer here


<--! The First Page where the image is browsed for uploading--->

<HTML>
<HEAD>
<TITLE>Upload example</TITLE>
</HEAD>
<BODY>

<FORM METHOD="post" ACTION="resultUpload.php" ENCTYPE="multipart/form-data">

<p><strong>File</strong><br>
<INPUT TYPE="file" NAME="img1" SIZE="30"></p>

<P><INPUT TYPE="submit" NAME="submit" VALUE="Send"></p>

</FORM>

</BODY>
</HTML>




/*resultupload.php*/
<? php

$ImgArr=array("image/pjpeg","image/gif","image/png");
$i=0;

if ($img1_name!="") {

   if($img1_size > 2000000) {
       echo "File size is bigger than 20kb!";
             exit;
     }

     while($i<3){
/* Change the relative path where you want to load images but the folder should be within the virtual
folder and put ./Yourfolder if it is in the same direcory where your page is currently located or ../yourfolder
if it is outside the folder   */
      if($ImgArr[$i]==$img1_type){
         copy("$img1","./Images/$img1_name")
       or die("No copy!");
       echo "File name : $img1_name <BR>";
       echo "File size :$img1_size <br>";
       echo "File Type :$img1_type <br>";
       exit;
 
      }

      $i++;
     }

   echo "Not A Image file!!!";
}

else
{

  die("No input file!");

}

?>



                       Anup
0
 
LVL 1

Author Comment

by:sviksna
ID: 6230468
This sample worked without any bugs. 10x a lot :)

Sandis.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

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

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question