Jump to content

Help in File Uploads.


oneplusdave

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.