DeanWhitehouse Posted May 7, 2008 Share Posted May 7, 2008 how can i get the name of an uploaded file, this is my code <?php if(isset($_POST['upload'])) { $target = "images/"; $image = $_POST['uploaded']; $imagename = $_POST['imagename']; $imagecaption = $_POST['imagecaption']; $user_check = mysql_num_rows(mysql_query("SELECT * FROM `hayleyimages` WHERE image_name = 1 ")); $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } if($user_check >= 1) { echo "$imagename already exists, please rename it."; } //If everything is ok we try to upload it else { //if($image && $imagename && $imagecaption) //{ mysql_query("INSERT INTO `hayleyimages` (image_link, image_name, image_caption, image_id) VALUES ( '$image','$imagename','$imagecaption', '')") or die('Error ' . mysql_error()); if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } //} //else //{ //echo "<br>Please make sure all fields are filled in."; //} } } ?> <form enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'] ?>" method="POST">Image Name: <input type="text" name="imagename" /><br />Image Caption: <input type="text" name="imagecaption" /><br /> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Submit" name="upload" /> </form> this "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; only echos The file has been uploaded Quote Link to comment https://forums.phpfreaks.com/topic/104634-solved-how-can-i-get-the-name-an-uploaded-file-and-the-extension-eg-jpg/ Share on other sites More sharing options...
DarkWater Posted May 7, 2008 Share Posted May 7, 2008 It's $_FILES['uploaded']['name'] in your case. =P Look: Please choose a file: <input name="uploaded" type="file" /><br /> To get the extension: $name = $_FILES['uploaded']['name']; $extension = substr($name, strrpos($name, "."), strlen($name)); Quote Link to comment https://forums.phpfreaks.com/topic/104634-solved-how-can-i-get-the-name-an-uploaded-file-and-the-extension-eg-jpg/#findComment-535526 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.