Solved

Uploading files

Posted on 2001-06-05
8
223 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 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

23 Experts available now in Live!

Get 1:1 Help Now