Jump to content

Recommended Posts

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.

 

 

Link to comment
https://forums.phpfreaks.com/topic/209513-help-in-file-uploads/
Share on other sites

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?

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.