So I tried to code a PHP upload form to upload some images into a folder on my site, but for SOME flippin' reason, it doesn't work! Please, somebody...tell me what I'm doing wrong! <?php $path = "/home/bgamer/public_html/media"; $url = "http://www.boldgamers.com/media"; if (!$_POST['file']) { echo '<form method="post" action="upload.php" enctype="multipart/form-data"><input type="file" name="file"> <input type="submit" value="Upload!"></form>'; } if ($_POST['file']) { $copy = copy ($_FILES["file"]["tmp_name"], $path."/".$_FILES["file"]["name"]); if ($copy == TRUE) { echo "<a href='".$url."/".$_POST["file"]."'>View your file!</a>"; } else { echo "Nope didnt go through; go back and try again!"; } } ?> Code (markup): Note: That IS upload.php also
use the move_uploaded_file function here's the code I normally use for uploading <?php $name = $_FILES['the_file']['name']; if (!$name) die('Sorry, an error has occured please try again'); $name = preg_replace("/\s/","_",$name);//make sure there are no spaces $size = $_FILES['the_file']['size']; $tmp_name = $_FILES['the_file']['tmp_name']; if (move_uploaded_file($tmp_name, "files/$name")) { echo "Upload Successful"; } else { echo "Sorry, an error has occured please try again"; } ?> Code (markup):
Well with my code no because for some reason the coding I'm using now causes an internal server error when I try it out with the directory CHMOD'ed.. :| I'm going be trying this guy's coding later tonight when I get off of work. Thanks!!! ^_^
Ok so I tried this code but it has no upload field...so it says Sorry, an error has occured please try again. :| Also, is there a way it can make a link to the image you just uploaded? Also, could it add numbers to the file name that it saves into the directory? Like it changes MarioBrosPic.jpeg to MariosBrosPic0101010101010101289273.jpeg? Thanks. ^_^