Can anyone tell me where i can find a script that allows user to upload pictures to my site? I don't need alot of fancy features, just upload and they will have the url link of the pictures.. and i can set the size limit. Anyone?
<?php // IMAGE SIZE $_IMAGESSIZE="60000"; // YOUR IMAGE DIRECTORY $_imagesdir="images/"; // remeber chmod 777 in this dir if(isset($_POST['addfiles'])) { $types = array("image/pjpeg","image/jpeg","image/gif","image/x-png","image/png","image/bmp"); // $uploadfile = $_FILES['fmage']['name']; $uploadfile = md5(time()).$_FILES['fmage']['name']; if ($_FILES['fmage']['size']>$_IMAGESSIZE) { $error.="Image is too big"; } if (!in_array($_FILES['fmage']['type'], $types)){ $error.="only images please"; $name = $_FILES['fmage']['name']; $type = $_FILES['fmage']['type']; $size = $_FILES['fmage']['size']; $tmp = $_FILES['fmage']['name']; $error.="i send ".$type." this files no are allowed to upload"; } if (empty($error)) { move_uploaded_file($_FILES['fmage']['tmp_name'],"".$_imagesdir."/$uploadfile"); $_OK="File uploaded :)"; } } echo $error."".$_OK; ?> <form method="POST" enctype="multipart/form-data" > <input type=file name="fmage"> <input type=submit name="addfiles" value="Send image" > </form> PHP: Best regards
Don't you need to check the file with is_uploaded_file (http://lv.php.net/manual/en/function.is-uploaded-file.php) before moving it for safety? To show the HTML, simply edit the message after move_uploaded_file is executed.
well please look the code # if (empty($error)) # { # move_uploaded_file($_FILES['fmage']['tmp_name'],"".$_imagesdir."/$uploadfile"); # $_OK="File uploaded "; # } tranlating this : if no have error in upload the script upload the image ok ? you use the same validation in forms , logins systems ... if have error the script only return the message and no execute the action !