jason360 Posted January 8, 2014 Share Posted January 8, 2014 Hey Guys, Just stuck on this php form to upload. I am trying to post a photo to the upload script. For some reason it seems that only the photo's filename is being passed on from the form to the upload script, but not the actual photo. Any help is much appreciated. My code: Form page: <?php include("image_upload_script.php"); ?> <form enctype="multipart/form-data" class="clearfix" action="" method="post"> <?php if($_SESSION['msg']['login-err']) { echo '<div class="err">'.$_SESSION['msg']['login-err'].'</div>'; unset($_SESSION['msg']['login-err']); } ?> Choose your file here: <input name="uploaded_file" type="file"/><br /><br /> <input type="submit" name="submit" value="Upload It" class="" /> </form> Upload script: <?php session_start(); $pid ='1000'; if($_POST['submit']=='Upload It') { // Access the $_FILES global variable for this specific file being uploaded // and create local PHP variables from the $_FILES array of information $fileName = $_POST["uploaded_file"]["name"]; // The file name $fileTmpLoc = $_POST["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_POST["uploaded_file"]["type"]; // The type of file it is $fileSize = $_POST["uploaded_file"]["size"]; // File size in bytes $fileErrorMsg = $_POST["uploaded_file"]["error"]; // 0 for false... and 1 for true $kaboom = explode(".", $fileName); // Split file name into an array using the dot $fileExt = end($kaboom); // Now target the last array element to get the file extension $fileName = $pid.".".$fileExt; //rename // Image handling after this, cut out for simplicity -------------------------------------------------- } ?> Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted January 8, 2014 Solution Share Posted January 8, 2014 Take a look at the comments in the code you yourself posted: // Access the $_FILES global variable for this specific file being uploaded // and create local PHP variables from the $_FILES array of information Quote Link to comment Share on other sites More sharing options...
jason360 Posted January 8, 2014 Author Share Posted January 8, 2014 Hey requinix. Thanks for helping a noob out! I thought the $_POST part of: if($_POST['submit']=='Upload It') had to match my variables. Works now! Quote Link to comment 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.