3raser Posted January 13, 2011 Share Posted January 13, 2011 After further research, I learned a bit more. But where do I put the ['extension'] part? echo "You cannot use a ". PATHINFO(basename($_FILES['file']['name']['extension'])) ." extension!"; Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/ Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 echo pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158672 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 echo pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); Didn't work. :/ Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158692 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 What do you get if you simply echo $_FILES['file']['name']? Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158698 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 What do you get if you simply echo $_FILES['file']['name']? Nothing shows up. Doesn't it need to be basename($_FILES['file']['name']) instead? The rest of my code uses that as the file name. Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158701 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 Shouldn't need to. pathinfo() will work even with a full path such as /var/www/htdocs/site/index.php. If there's nothing in the array element, that would be the problem. Post the chunk of code that uses this, from the point where the file is picked out of the form data through where pathinfo() is used. Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158702 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 Shouldn't need to. pathinfo() will work even with a full path such as /var/www/htdocs/site/index.php. If there's nothing in the array element, that would be the problem. Post the chunk of code that uses this, from the point where the file is picked out of the form data through where pathinfo() is used. start_upload.php <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { echo '<form enctype="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="10000000 byte" /> Choose a Plugin to Upload: <input name="file" type="file" /><br /> <b>Title:</b> <input type="text" name="title" maxlength="40"><br/> <b>Description</b><br/><textarea name="description" cols="45" rows="25" maxlength="2300"></textarea> <br/> <input type="submit" value="Upload Plugin" /> </form>'; echo "<br/><br/>"; echo "NOTE: Uploading any harmful programs and/or files that can invade another users privacy, harm their computer, or uploading any files like malware, viruses, or trojans will result in an INSTANT, PERMANENT, IP Ban."; } ?> <? include("includes/footer.php"); ?> upload.php <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $user = $_SESSION['SESSION']; $target_path = "mods/"; $target_path = $target_path . basename( $_FILES['file']['name']); if(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION)==".zip") { if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; $_FILES['file']['name'] = $output; echo "The mod ". basename( $_FILES['file']['name']). " has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>"; echo pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION); mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } else { echo "You cannot use a ". pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION) ." extension!"; echo $_FILES['file']['name']; } } include("includes/footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158721 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 This solved it: echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension!"; Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158727 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 You're changing the contents of $_FILES['file']['name'] on this line: $_FILES['file']['name'] = $output; Is that part of your file-renaming routine? If it is, you'll need to check the extension before that point. Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158730 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 You're changing the contents of $_FILES['file']['name'] on this line: $_FILES['file']['name'] = $output; Is that part of your file-renaming routine? If it is, you'll need to check the extension before that point. Nope, it's not changing anything important. :/ It worked before, now it isn't. Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158737 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 I has to be changing something important. $output would either contain an integer, or possibly an empty string or NULL value. None of those are file names. Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158747 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 I has to be changing something important. $output would either contain an integer, or possibly an empty string or NULL value. None of those are file names. Yes, it's an integer. But where it checks and displays the extensions are out of reach. (Checks = above $output, display is in another { } (dunno whats it's called) - And this is the latest code) <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $user = $_SESSION['SESSION']; $target_path = "mods/"; $target_path = $target_path . basename( $_FILES['file']['name']); if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); echo "The mod ". basename($_FILES['file']['name']) . " has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>"; $output = $finish_query['COUNT(id)'] + 1; $_FILES['file']['name'] = $output; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } else { echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension! .zip is currently the only filed extension allowed."; } } include("includes/footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158767 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 I just pasted in your latest code, indented it properly, and it made more sense. It seems to work for me. When I try to use a file with an extension other than .zip, I get the error message. Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158782 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 I just pasted in your latest code, indented it properly, and it made more sense. It seems to work for me. When I try to use a file with an extension other than .zip, I get the error message. But if you DO use a zip, is gives you the error message. But it says: You cannot use a . extension! .zip is currently the only filed extension allowed. And also, thats just the way I code. I don't know what to do to improve it... Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158795 Share on other sites More sharing options...
Pikachu2000 Posted January 13, 2011 Share Posted January 13, 2011 No, not for me it doesn't. I had to comment out your db queries, but otherwise I just pasted your code into my dev box. When I try a .pdf: You cannot use a .pdf extension! .zip is currently the only filed extension allowed. With a .zip I get the There was an error uploading the file, please try again! because I didn't replicate your directory structure, and no error for the extension. Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158796 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 <?php session_start(); include("includes/mysql.php"); include("includes/config.php"); ?> <title><?php echo $title; ?></title> <?php echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; if(!$_SESSION['user']) { echo "Your not allowed to upload plugins! <a href='index.php'>Go Home</a> or <a href='register.php'>Make an account</a>."; } else { echo "<a href='start_upload.php'>Upload</a> | <a href='search.php'>Search & Browse</a> | <a href='/news'>News & Announcements</a> | <a href='logout.php'>Logout</a><hr>"; $description = $_POST['description']; $description = mysql_real_escape_string($description); $ip = $_SERVER['REMOTE_ADDR']; $date = date('m-d-y'); $title = $_POST['title']; $title = mysql_real_escape_string($title); $user = $_SESSION['SESSION']; $target_path = "mods/"; $query = mysql_query("SELECT COUNT(id) FROM mods"); $finish_query = mysql_fetch_assoc($query); $output = $finish_query['COUNT(id)'] + 1; $_FILES['file']['name'] = $output; $target_path = $target_path . basename( $_FILES['file']['name']); if(pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION)=="zip") { if(move_uploaded_file($output, $target_path)) { echo "The mod ". basename($_FILES['file']['name']) . " has been uploaded. Check it out <a href='mods/". $output ."'>HERE.</a>"; mysql_query("INSERT INTO mods VALUES('', '$ip', '$date', '$title', '$description', '$user')"); } else{ echo "There was an error uploading the file, please try again!"; } } else { echo "You cannot use a .". pathinfo(basename($_FILES['file']['name']), PATHINFO_EXTENSION) ." extension! .zip is currently the only filed extension allowed."; } } include("includes/footer.php"); ?> How do I get it so it will upload the file name as $output, instead of basename($_FILES['file]['name']) Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1158798 Share on other sites More sharing options...
3raser Posted January 13, 2011 Author Share Posted January 13, 2011 Bump Link to comment https://forums.phpfreaks.com/topic/224259-pathinfo-error/#findComment-1159082 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.