LemonInflux Posted September 14, 2007 Share Posted September 14, 2007 <? //print_r($_POST); $folder = $_GET['fol']; if($_POST["action"] == "Upload Image") { unset($imagename); if(!isset($_FILES) && isset($HTTP_POST_FILES)) $_FILES = $HTTP_POST_FILES; if(!isset($_FILES['image_file'])) $error["image_file"] = "An image was not found."; $imagename = basename($_FILES['image_file']['name']); //echo $imagename; if(empty($imagename)) $error["imagename"] = "The name of the image was not found."; if(empty($error)) { $newimage = ($f_user .'/'. $folder .'/'. $imagename); //echo $newimage; $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) $error["result"] = "There was an error moving the uploaded file."; } } ?> <center><form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>"> <input type="file" name="image_file" size="20"> <br><br><input type="submit" value="Upload File" name="action"> </form></center> <div align="center"> <div align="center"><br> <? if(is_array($error)) { while(list($key, $val) = each($error)) { echo $val; echo "<br>\n"; } } ?> <?php $files = array(); $dir = opendir($f_user .'/'. $folder); while(($file = readdir($dir)) !== false) { if($file !== '.' && $file !== '..' && !is_dir($file)) { $files[] = $file; } } closedir($dir); natcasesort($files); echo "<ul>\n"; for($i=0; $i<count($files); $i++) { if($files[$i] != "index.php") echo '<li><a href="'. $f_user .'/'. $folder .'/'. $files[$i] .'">'. $files[$i] .'</a> - <a href=\delfol.php?del='. $files[$i] .'>Delete</a></li>'; } echo "</ul>\n"; ?> Explanation I want this to list a subfolder in the user's directory. It is an image hoster. Before anyone asks, this is completely flat, no MySQL. Basically, the user ($f_user, as defined in-script (not shown)), has a folder called $f_user (their username). within that, they have a folder called $folder (the url comes out like blah.com/blah/folderview.php?fol=foldername, so the code gets the foldername). Now, I want this code to list $folder's contents, and allow the user to upload to $folder. So far, I have the upload form showing, but when a file is uploaded, it isn't uploaded, neither is it shown. Much appreciated if anyone can work this one out. Thanks in advance, Tom. PS, for any further queries as to what the variables mean, just post. Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/ Share on other sites More sharing options...
chronister Posted September 14, 2007 Share Posted September 14, 2007 Try removing the @ before the line move_uploaded_file, it is an error suppresor. In this case you wanna see what kind of error you get. I have found that any folders used for uploading need to be set to chmod 777. There may be another way but I don't know of it right now. Check permissions and try to get the error message. maybe try this if(move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage) { echo 'Upload Successful'; } else { $error["result"] = "There was an error moving the uploaded file."; } I just noticed that you have a syntax error if(empty($error)) { $newimage = ($f_user .'/'. $folder .'/'. $imagename); //echo $newimage; $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage); if(empty($result)) { // you forgot this bracket right here. $error["result"] = "There was an error moving the uploaded file."; } } Nate Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348473 Share on other sites More sharing options...
LemonInflux Posted September 14, 2007 Author Share Posted September 14, 2007 Blank screen after adding that :\ Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348493 Share on other sites More sharing options...
Jessica Posted September 14, 2007 Share Posted September 14, 2007 <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> Add to the top of the page. Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348494 Share on other sites More sharing options...
LemonInflux Posted September 14, 2007 Author Share Posted September 14, 2007 OK, the uploader showed up as supposed to (but without the files listed), but this error line was below: Notice: Undefined variable: error in e:\domains\r\reflexprojects.net\user\htdocs\rs\upload\folderview.php on line 69 line 69 is 'if(is_array($error))' Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348496 Share on other sites More sharing options...
LemonInflux Posted September 14, 2007 Author Share Posted September 14, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348499 Share on other sites More sharing options...
chronister Posted September 14, 2007 Share Posted September 14, 2007 $HTTP_POST_FILES; This is no longer good. I think that for PHP4 and higher it should be $_FILES[]; That error will not cause the script to break and fail to upload the file. I don't mean to insult you, but your code is terrible. You set $_FILES to $HTTP_POST_FILES. WHY???? $_FILES is already a superglobal, why set it to a deprecated var?? Your syntax is hard to read and it is missing several }'s also, you don't close your div tags. No wonder you are having such a hard time, your code is just plain bad. Code to standards. HTML has specific standards, so for the sake of the web community, follow them. Make sure your using the correct syntax in PHP Try fixing the syntax. a proper if statement should be <?php if(1 < 3) { echo 'it is less'; } ?> Use the proper brackets to close it out, and also get into the habit of indenting the code as it makes it easier to read and find errors. I fixed a few things, try this and tell me if it helps <? //print_r($_POST); $folder = $_GET['fol']; if($_POST["action"] == "Upload Image") { unset($imagename); if(!isset($_FILES['image_file'])) { $error["image_file"] = "An image was not found."; } $imagename = basename($_FILES['image_file']['name']); //echo $imagename; if(empty($imagename)) { $error["imagename"] = "The name of the image was not found."; } if(empty($error)) { $newimage = ($f_user .'/'. $folder .'/'. $imagename); //echo $newimage; if(move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage)) { echo 'File Uploaded successuflly'; } else { $error["result"] = "There was an error moving the uploaded file."; } } } ?> <center> <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>"> <input type="file" name="image_file" size="20"> <br> <br> <input type="submit" value="Upload File" name="action"> </form> </center> <div align="center"> <div align="center"> <br> <? if(is_array($error)) { foreach($error as $key=>$val) { echo $val; echo "<br>\n"; } } ?> <?php $files = array(); $dir = opendir($f_user .'/'. $folder); while(($file = readdir($dir)) !== false) { if($file !== '.' && $file !== '..' && !is_dir($file)) { $files[] = $file; } } closedir($dir); natcasesort($files); echo "<ul>\n"; for($i=0; $i<count($files); $i++) { if($files[$i] != "index.php") echo '<li><a href="'. $f_user .'/'. $folder .'/'. $files[$i] .'">'. $files[$i] .'</a> - <a href=\delfol.php?del='. $files[$i] .'>Delete</a></li>'; } echo "</ul>\n"; ?> Nate Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348534 Share on other sites More sharing options...
LemonInflux Posted September 14, 2007 Author Share Posted September 14, 2007 Notice: Undefined index: action in e:\domains\r\reflexprojects.net\user\htdocs\rs\upload\folderview.php on line 30 (which is if($_POST["action"] == "Upload Image") ), Notice: Undefined variable: error in e:\domains\r\reflexprojects.net\user\htdocs\rs\upload\folderview.php on line 76 (which is if(is_array($error)) ) Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348618 Share on other sites More sharing options...
LemonInflux Posted September 14, 2007 Author Share Posted September 14, 2007 And as for the code, a lot of it was altered and improved by people here. Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348619 Share on other sites More sharing options...
chocopi Posted September 14, 2007 Share Posted September 14, 2007 You really shouldn't bump your topic 10 minutes after a post Im not sure on this but either $_POST['action'] has no value or you should use $_POST['action'] instead of $_POST["action"] and the second part is kinda self-explanatory Undefined variable: error ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348636 Share on other sites More sharing options...
LemonInflux Posted September 14, 2007 Author Share Posted September 14, 2007 That value is created after uploading something. As for the second bit, sorted that. Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348643 Share on other sites More sharing options...
LemonInflux Posted September 15, 2007 Author Share Posted September 15, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348934 Share on other sites More sharing options...
LemonInflux Posted September 15, 2007 Author Share Posted September 15, 2007 bump. Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348978 Share on other sites More sharing options...
LemonInflux Posted September 15, 2007 Author Share Posted September 15, 2007 Never mind, worked it out myself. Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-348981 Share on other sites More sharing options...
LemonInflux Posted October 2, 2007 Author Share Posted October 2, 2007 OK, the pages are both showing and everything, but I still cannot log in.. Quote Link to comment https://forums.phpfreaks.com/topic/69354-solved-wheres-the-error/#findComment-360137 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.