luismc2007 Posted May 20, 2013 Share Posted May 20, 2013 Hi: I´m trying to make my own code for upload images using php to my server for my webpage, but I don´t know why the code doesn´t work at 100%. I know that its works until a point but not more away... Can you help me?? I have two files: an html and php called "form.html" and "sube.php" that I post here... And now explain what I´m try to do... [ File: form.html ] <form action="sube.php" method="post" enctype="multipart/form-data">Sube un archivo:<br /><input type="file" name="archivo" id="archivo" /><br /><input type="submit" name="boton" value="Subir" /></form> [ File: sube.php ] <?phpecho "Name of image: ".$_FILES["archivo"]["name"];echo "<br />"; $tamano = $_FILES["archivo"]["size"];echo "Size of image: ".$_FILES["archivo"]["size"]; // here always an errorecho "<br>"; $t_max="50000000000";echo "Maximum size:";echo "$t_max <br>"; if( $tamano < $t_max){$destino = "fotogal/grandes";$sep=explode('image/',$_FILES["archivo"]["type"]); if($_FILES["archivo"]["type"] == "gif" || $_FILES["archivo"]["type"] == "jpg" ) move_uploaded_file ( $_FILES["archivo"]["tmp_name"], $destino . '/' .$_FILES["archivo"]["name"]); }else echo "No way..."; // OUT}else { echo "too much weight of image."; } ?> The case of this is that always i reach the same point and don´t know how to go further... The point is that always I receive: Name.."ok"... Size: This item is completely different of the weight of the image And... No way. This is always my result. Can you help me with this code????? I would like to upload my own images, but I´m not able to do it... and don´t know why. Thanks a lot. regards Quote Link to comment https://forums.phpfreaks.com/topic/278205-upload-images-with-php/ Share on other sites More sharing options...
jazzman1 Posted May 20, 2013 Share Posted May 20, 2013 There are erors in your sube.php file: Try this: sube.php <?php echo "Name of image: " . $_FILES["archivo"]["name"]; echo "<br />"; $tamano = $_FILES["archivo"]["size"]; echo "Size of image: " . $_FILES["archivo"]["size"]; // here always an error echo "<br>"; $t_max = "50000000000"; echo "Maximum size:"; echo "$t_max <br>"; echo "File type:"; echo $_FILES["archivo"]["type"].'<br />'; if ($_FILES['archivo']['error'] === 0) { if ($tamano < $t_max) { $destino = "fotogal/grandes"; //get a file extension $file_ext = basename($_FILES["archivo"]['name']); // check the file extension in php $pattern = '/^.*\.(jpg|jpeg|gif)$/i'; if (!preg_match($pattern, $file_ext)) { echo "ERROR: You must select a valid image file!"; exit; } if(move_uploaded_file($_FILES["archivo"]["tmp_name"], $destino . '/' . $_FILES["archivo"]["name"])){ echo "Upload success"; } else { echo 'Upload failed.'; } } else { echo "too much weight of image."; } } else { echo "ERROR: Some error(s) was finded in that file"; } Quote Link to comment https://forums.phpfreaks.com/topic/278205-upload-images-with-php/#findComment-1431276 Share on other sites More sharing options...
Solution luismc2007 Posted May 21, 2013 Author Solution Share Posted May 21, 2013 Perfect. Its running now. Thanks.!! Quote Link to comment https://forums.phpfreaks.com/topic/278205-upload-images-with-php/#findComment-1431318 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.