oneplusdave Posted August 1, 2010 Share Posted August 1, 2010 I am relatively new to PHP, so I need help why this script is not functioning **T if ($actionis=='Add Resource'){ //declaration of directory where files are saved if(isset($_POST['file'])) { //setting of variables $uploaddir = "resources/"; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fileErr = $_FILES['userfile']['error']; $filePath= $uploaddir . basename($_FILES['userfile']['name']); global $filePath; //filters extension filename $fileX = strrchr($fileName,"."); /* * UPLOAD FILTERING OPTIONS */ if ($fileSize>1000000){ die ("File too large! Must be below 1Mb."); } else{ if (($fileX==".txt")||($fileX==".doc")||($fileX==".docx")||($fileX==".pdf")||($fileX==".ppt")||($fileX==".pptx")){ if (move_uploaded_file($_FILES['userfile']['tmp_name'], $filePath)){ echo "<code>SUCCESS! File Uploaded.</code> ".$fileErr; } else{ echo "<code class='red'>Upload Failed.</code>"; } } else{ die ("Wrong file format!"); } } } The above script does not generate an error. But my problem is that I cannot save the uploaded file into my selected directory. Quote Link to comment Share on other sites More sharing options...
bh Posted August 1, 2010 Share Posted August 1, 2010 Its strange. Has your PHP's user permission to write that path "$filePath"? (But it must generate a permission denied error message...) Is your error displaying options are enable (error_reporting and display error)? Quote Link to comment Share on other sites More sharing options...
oneplusdave Posted August 2, 2010 Author Share Posted August 2, 2010 Its strange. Has your PHP's user permission to write that path "$filePath"? (But it must generate a permission denied error message...) Is your error displaying options are enable (error_reporting and display error)? I've checked my phpinfo.php, the error_reporting value is set to 6135, what does that mean? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted August 2, 2010 Share Posted August 2, 2010 http://www.php.net/manual/en/errorfunc.constants.php The value 6135 will be a combination of the error level codes added up. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 2, 2010 Share Posted August 2, 2010 Set error_reporting to E_ALL at the top of your script. error_reporting(E_ALL); That may give you some errors. Also, what is the point of this line: global $filePath; Why are you using the global keyword? Seems rather pointless to me. Quote Link to comment Share on other sites More sharing options...
oneplusdave Posted August 2, 2010 Author Share Posted August 2, 2010 Set error_reporting to E_ALL at the top of your script. error_reporting(E_ALL); That may give you some errors. Also, what is the point of this line: global $filePath; Why are you using the global keyword? Seems rather pointless to me. I used $global because I would like to make the variable available at certain pages. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted August 2, 2010 Share Posted August 2, 2010 Read up on globals. Also, for future reference, see why globals can be bad. 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.