Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
GOOGLE AI PRO - 18 Month - Rs.500.00
Sanathbh
Updated:
Yesterday at 8:25 PM
📸 SIGMA 85mm F1.4 DG HSM | Art — Nikon Mount
romeshnonis
Updated:
Wednesday at 3:56 PM
Ad icon
Singapore V2Ray VPN for Tunneling
hu KANNA
Updated:
Monday at 9:03 PM
Plan your Crypto & Forex entries before you take the trade
romeshnonis
Updated:
Monday at 3:20 AM
RHCSA, RHCE, AWS, Docker, Kubernetes Training
Sanjeewani95
Updated:
Sep 8, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
Computers & Internet
Software Development
i need a help for this php code
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="viraj_slk" data-source="post: 5242712" data-attributes="member: 51932"><p>machn mama php walata very new. but i did a simple uploader recently. is this what you are looking for?</p><p></p><p>-------------------------------[PHP]<?php</p><p></p><p>/**</p><p> * @author 'me'</p><p> * @copyright 2009</p><p> */</p><p></p><p></p><p> define("MAX_FILE_SIZE", 1048000);</p><p> </p><p> //Funciton to print blank rows.</p><p> function br(){ print "<br />";}</p><p> </p><p> if ( isset($_FILES['fupload']) ){</p><p> print "<p> Thanks for the upload.. processing your file now.. </p>";</p><p> br();</p><p> </p><p> $file_type = $_FILES['fupload']['type'];</p><p> if ( ( $file_type == "image/jpeg") || ($file_type == "image/pjpeg") || ($file_type == "image/gif") ) {</p><p> </p><p> //To check if the file size exceeds the specified limit..</p><p> if ($_FILES['fupload']['size'] > MAX_FILE_SIZE)</p><p> {</p><p> print "Your file size exceed the maximum specified size of ".MAX_FILE_SIZE;</p><p> exit;</p><p> }</p><p></p><p> //Now we just print some info. about the file to the screen</p><p> print "file name: ".$_FILES['fupload']['name']; br();</p><p> print "file size: ".$_FILES['fupload']['size']; br();</p><p> print "file type: ".$_FILES['fupload']['type']; br();</p><p> print "file tmp_name(temp path): ".$_FILES['fupload']['tmp_name']; br();</p><p> </p><p> //Specifying source and the target (destination) for our file</p><p> $source = $_FILES['fupload']['tmp_name'];</p><p> $target = "upload/".$_FILES['fupload']['name'];</p><p> </p><p> //Moving file to the destination</p><p> move_uploaded_file($source, $target);</p><p> </p><p> //Prints the image according to its original height and width</p><p> $img_size = getImageSize($target);</p><p> $imgstr = "<p> <img src=\"$target\" width=\"$img_size[0]\" ";</p><p> $imgstr .= " height=\"$img_size[1]\" alt = \"uploaded image here\" /> </p>";</p><p> </p><p> //Display the successfully uploaded image </p><p> print $imgstr;</p><p> }</p><p> else{</p><p> //Show error message</p><p> print "Your file type ".$_FILES['fupload']['type']." cannot be proecessed. <br> Please upload as .jpeg or .gif";</p><p> }</p><p> }</p><p> else{</p><p> #If the user arrives on the web page for the first time -> then '$_FILES['fupload'])' is not set</p><p> print "Welcome. Please upload any ( .jpg/.jpeg/.gif ) picture files."; br();</p><p> }</p><p></p><p></p><p>?></p><p></p><p> <!DOCTYPE html PUBLIC </p><p> "-//W3C//DTD XHTML 1.0 Strict//EN" </p><p> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> </p><p> <html></p><p> <head></p><p> <title>File uploader</title></p><p> </title></p><p> <body></p><p> </p><p><form enctype="multipart/form-data" </p><p> action="<?php print $_SERVER['PHP_SELF']?>" method="post"></p><p> <p></p><p> <input type="file" name="fupload" /><br/></p><p> <input type="submit" value="upload!" /> </p><p> </p></p><p> </form></p><p> </p><p> </body></p><p> </html></p><p> [/PHP]</p><p></p><p>this is pretty simple code to let user upload images. when the upload is successful, you can write something into your database. I guess something like the location of the image within your server.</p><p></p><p>be careful when you let people upload images or whatever. that's why i check whether the files are really in image format. Still it's better if you can replace some things in the file names with underscore.</p><p></p><p>for example, a very popular way of shell upload (eg. c99 shell ) is to rename the php file to something like pretty.php.jpg</p><p></p><p>when you upload this to some servers, some servers try to process the php code that's really in the file. but some servers do not do that. so its good if you can extract the file name, which in this case is 'pretty.php' and replace any unnecessary characters such as '.' with underscores. there is a better tool to check if uploaded files are really image files. i can't remember it now. google is your friend <img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /></p><p></p><p>Hope this helps</p></blockquote><p></p>
[QUOTE="viraj_slk, post: 5242712, member: 51932"] machn mama php walata very new. but i did a simple uploader recently. is this what you are looking for? -------------------------------[PHP]<?php /** * @author 'me' * @copyright 2009 */ define("MAX_FILE_SIZE", 1048000); //Funciton to print blank rows. function br(){ print "<br />";} if ( isset($_FILES['fupload']) ){ print "<p> Thanks for the upload.. processing your file now.. </p>"; br(); $file_type = $_FILES['fupload']['type']; if ( ( $file_type == "image/jpeg") || ($file_type == "image/pjpeg") || ($file_type == "image/gif") ) { //To check if the file size exceeds the specified limit.. if ($_FILES['fupload']['size'] > MAX_FILE_SIZE) { print "Your file size exceed the maximum specified size of ".MAX_FILE_SIZE; exit; } //Now we just print some info. about the file to the screen print "file name: ".$_FILES['fupload']['name']; br(); print "file size: ".$_FILES['fupload']['size']; br(); print "file type: ".$_FILES['fupload']['type']; br(); print "file tmp_name(temp path): ".$_FILES['fupload']['tmp_name']; br(); //Specifying source and the target (destination) for our file $source = $_FILES['fupload']['tmp_name']; $target = "upload/".$_FILES['fupload']['name']; //Moving file to the destination move_uploaded_file($source, $target); //Prints the image according to its original height and width $img_size = getImageSize($target); $imgstr = "<p> <img src=\"$target\" width=\"$img_size[0]\" "; $imgstr .= " height=\"$img_size[1]\" alt = \"uploaded image here\" /> </p>"; //Display the successfully uploaded image print $imgstr; } else{ //Show error message print "Your file type ".$_FILES['fupload']['type']." cannot be proecessed. <br> Please upload as .jpeg or .gif"; } } else{ #If the user arrives on the web page for the first time -> then '$_FILES['fupload'])' is not set print "Welcome. Please upload any ( .jpg/.jpeg/.gif ) picture files."; br(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>File uploader</title> </title> <body> <form enctype="multipart/form-data" action="<?php print $_SERVER['PHP_SELF']?>" method="post"> <p> <input type="file" name="fupload" /><br/> <input type="submit" value="upload!" /> </p> </form> </body> </html> [/PHP] this is pretty simple code to let user upload images. when the upload is successful, you can write something into your database. I guess something like the location of the image within your server. be careful when you let people upload images or whatever. that's why i check whether the files are really in image format. Still it's better if you can replace some things in the file names with underscore. for example, a very popular way of shell upload (eg. c99 shell ) is to rename the php file to something like pretty.php.jpg when you upload this to some servers, some servers try to process the php code that's really in the file. but some servers do not do that. so its good if you can extract the file name, which in this case is 'pretty.php' and replace any unnecessary characters such as '.' with underscores. there is a better tool to check if uploaded files are really image files. i can't remember it now. google is your friend :) Hope this helps [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom