Solved

Uploading files

Posted on 2001-06-05
8
233 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wamp versus xampp 4 43
only allow numbers with preg match 4 24
phpmailer in WHILE loop - weird results 10 27
Configuring a checkbox in CSS and php 18 30
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to count occurrences of each item in an array.
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now