Solved

Uploading files

Posted on 2001-06-05
8
244 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

809 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