multiple file upload uploads only single post - php

I have the following code for multiple file uploads using php and mysql. But for some reason , if 'n' files are selected, only the last(or 'n'th) file seems to be uploaded..
Here are the respective files:
HTML
<form enctype="multipart/form-data" method="post" action="<?php echo htmlentities($_SERVER["PHP_SELF"]);?>">
<div class="form-group">
<textarea class="form-control" name="postbox" id="pbox"></textarea>
</div>
<h5><strong>Add media:</strong></h5>
<input type="file" name="pfile[]" multiple="multiple" accept="image/*,audio/*,video/*"><br/>
<button type="submit" class="btn btn-success" name="psubmit">Post!</button>
</form>
<div class="posts">
<?php
if(isset($_POST['postbox'])){
$ps = escape($_POST['postbox']);
}
include_once('includes/uploadfile.php'); ?>
</div>
includes/uploadfile.php
<?php ob_start();
require_once 'core/init.php';
if(isset($_POST['psubmit']))
{
foreach ($_FILES['pfile']['tmp_name'] as $key=>$value)
{
$pfname = $_FILES["pfile"]['name'][$key];
$pftype = $_FILES['pfile']['type'][$key];
$pfsize = $_FILES['pfile']['size'][$key];
$pftmploc = $_FILES['pfile']['tmp_name'][$key];
$pferror = $_FILES['pfile']['error'][$key];
$blast = explode(".", $pfname);
$pfextn = end($blast);
if (!empty($ps) && empty($pfname))
{
$dbfname = NULL;
$abc = $get->addPost($a, $ps, $pfname);
header('location:'.escape($_SERVER['PHP_SELF'])); exit;
}
else if (!empty($pfname) && !empty($ps))
{
//list($width, $height) = getimagesize($pftmploc);
if($pfsize > 20971520)
{
echo "ERROR: Your file was larger than 20 Megabytes in size.";
unlink($pftmploc);
exit();
}
else if(!preg_match("/.(gif|jpg|png|mp3|mp4|avi)$/i", $pfname) )
{
echo "ERROR: Restricted file format!Kindly stick to these formats alone:gif,jpg,png,mp3,mp4,avi";
unlink($pftmploc);
exit();
}
else if($pferror == 1)
{ // if file upload error key is equal to 1
echo "ERROR: An error occured while processing the file. Try again.";
exit();
}
}
$dbfname = rand(100000000000,999999999999).$pfname;
$updir = "ups/posts/";
$arraymov = array();
array_push($arraymov, $dbfname);
$movrslt = move_uploaded_file($pftmploc,$updir.$dbfname);
if($movrslt != true)
{
echo 'ERROR: File upload failed. Try again!';
exit();
}
}
$abc = $get->addPost($a, $ps, implode(',',$arraymov));
header('location:'.escape($_SERVER['PHP_SELF'])); exit;
}
?>
File upload function:
public function addPost($user_id,$status,$file_path){
$query = $this->_db->prepare("INSERT INTO postsinitial (puid, pstatus, postimg) VALUES (:k, :l, :m)");
$query->bindValue(':k',$user_id);
$query->bindValue(':l', nl2br(htmlentities($status, ENT_QUOTES, 'UTF-8')));
$query->bindValue(':m',$file_path);
$query->execute();
$rsizes = $query->rowCount();
if ($rsizes > 0) {
return true;
}
else
{
return false;
}
}
I've tried to code to insert each file path as a comma-separated array of values so that a user can upload multiple images for only one record in database.This is important!
Tnx in advance!

Looks like you have got the logic wrong. You have to execute move_uploaded_file() within the same foreach() that loops through the $_FILES array.
...
echo "ERROR: An error occured while processing the file. Try again.";
exit();
}
}
move_uploaded_file(...
}
What you have done is trying to execute move_uploaded_file() in a separate foreach block using $pftmploc variable as the temporary file path. But since that variable was assigned inside the previous foreach() loop, it represents the last element of the uploaded files array. Thats why you are not getting all the files uploaded.

The foreach does not look quite right. Try this snippet in your uploadfile.php in place of the foreach part. It builds your loop a little differently, checking the tmp_name to see if the loop should continue.
if(isset($_POST['psubmit']))
{
$imagearray = array();
for ($i = 0; $_FILES['pfile']['tmp_name'][$i] $i++)
{
$pfname = $_FILES["pfile"]['name'][$i];
$pftype = $_FILES['pfile']['type'][$i];
$pfsize = $_FILES['pfile']['size'][$i];
$pftmploc = $_FILES['pfile']['tmp_name'][$i];
$pferror = $_FILES['pfile']['error'][$i];
$blast = explode(".", $pfname);
$pfextn = end($blast);
array_push($imagearray, $pfname);
if (!empty($ps) && empty($pfname))
{ ...

Related

Is this .php outdated and causing my page to throw an error?

For a game that I am an admin on, the maps upload page will always throw the "There was an error with your upload. Please try again." error. I did not write the code, but am in a position to to fix some things (all of the devs are no where to be found to try to help fix the problem). If the code is not an issue, what should I be looking at to try and solve the issue? Thanks!
Code for the page:
<?php
if (!isset($_SESSION['User'])) // we don't want guests to upload maps
{
header("Location: /account");
exit(0);
}
// Handle map file upload
$errormessage = "";
if (isset($_FILES['mapfile']) and $_FILES['mapfile']['name'] != "")
{
if ($_FILES['mapfile']['error'] != 0 or $_FILES['mapfile']['type'] != "application/octet-stream" or $_FILES['mapfile']['size'] < 1 or $_FILES['mapfile']['size'] > 64000)
{
$errormessage = "There was an error with your upload. Please try again.";
} else
{
$_FILES['mapfile']['name'] = filter_var($_FILES['mapfile']['name'], FILTER_SANITIZE_STRING);
$_FILES['mapfile']['name'] = str_replace(" ", "_", $_FILES['mapfile']['name']);
$_FILES['mapfile']['name'] = str_replace("(", "", $_FILES['mapfile']['name']);
$_FILES['mapfile']['name'] = str_replace(")", "", $_FILES['mapfile']['name']);
if (strpos($_FILES['mapfile']['name'], "ACG") !== false or preg_filter("/[\d|\w|\.|\-|\(|\)]/i", "", $_FILES['mapfile']['name']) != "" or substr(strtolower($_FILES['mapfile']['name']), -4, 4) != ".map")
{
$errormessage = "Invalid map filename.";
} else
// if (file_exists("public/maps/".$_FILES['mapfile']['name']))
// {
// $errormessage = "Map filename already exists in filesystem.";
// } else
{
try
{
$map = new Map($_FILES['mapfile']['tmp_name']);
} catch (Exception $e)
{
$errormessage = "File is not a valid map: ".$e->getMessage();
}
}
if ($errormessage == "")
{
$mapquery = DB::selectArray("SELECT * FROM maps WHERE Mapfile='{$_FILES['mapfile']['name']}' LIMIT 1");
if (sizeof($mapquery) > 0) DB::query("DELETE FROM maps WHERE Mapfile='{$_FILES['mapfile']['name']}' LIMIT 1");
$newmap = [];
$newmap['Mapfile'] = $_FILES['mapfile']['name'];
$newmap['Mapname'] = $map->mapinfo['name'];
$newmap['Gamemode'] = $map->mapinfo['gamemode'];
$newmap['DescriptionRaw'] = $map->mapinfo['description'];
$newmap['Description'] = $map->generateDescription(str_replace(".map", "", $_FILES['mapfile']['name']));
$newmap['Numteams'] = $map->mapinfo['numteams'];
$newmap['Mapsize'] = $map->mapinfo['tilecount'];
$newmap['Flagcount'] = $map->mapinfo['neutralflags'] + $map->mapinfo['greenflags'] + $map->mapinfo['redflags'] + $map->mapinfo['blueflags'] + $map->mapinfo['yellowflags'];
$newmap['Switchcount'] = $map->mapinfo['switches'];
$newmap['Turretcount'] = $map->mapinfo['turrets'];
$newmap['Warpcount'] = $map->mapinfo['warps'];
$newmap['Views'] = 0;
$newmap['Downloads'] = 0;
$newmap['Votes'] = 0;
$newmap['LastPlayed'] = null;
if (DB::saveArray("maps", $newmap))
{
if (move_uploaded_file($_FILES['mapfile']['tmp_name'], "public/maps/".$_FILES['mapfile']['name']))
{
chmod("public/maps/".$_FILES['mapfile']['name'], 0755);
imagepng($map->createImage(), "public/maps/images/".str_ireplace(".map",".png",$_FILES['mapfile']['name']));
imagepng($map->createCroppedImage(), "public/maps/croppedimages/".str_ireplace(".map",".png",$_FILES['mapfile']['name']));
$errormessage = "Map successfully added to database.<br/><br/><a href='/maps/?map={$_FILES['mapfile']['name']}'>{$_FILES['mapfile']['name']}</a> ";
function getmaplist()
{
$maps = [];
$mapPaths = glob("public/maps/*.map");
foreach ($mapPaths as $map)
{
$map = basename($map);
$maps[$map] = substr($map, 0, -4);
}
sort($maps, SORT_NATURAL | SORT_FLAG_CASE);
return $maps;
};
Cache::put("list of maps", getmaplist());
} else
{
$errormessage = "Error uploading map file.";
}
} else
{
$errormessage = "Error adding map to database.";
}
}
}
}
?>
<?php require_once("pages/header.php"); ?>
<div id='mapuploadpage'>
<form action="/mapupload" method="POST" enctype="multipart/form-data">
<h1>Upload a Map</h1>
<input type="hidden" name="MAX_FILE_SIZE" value="64000" />
<input type="file" name="mapfile" id="mapfile" />
<input type="submit" name="upload" id="uploadbutton" value="Upload" />
<div id="uploadmessage"><?php echo $errormessage; ?></div>
</form>
</div>
<?php require_once("pages/footer.php"); ?>
As you can see in the code,
if ($_FILES['mapfile']['error'] != 0 or $_FILES['mapfile']['type'] != "application/octet-stream" or $_FILES['mapfile']['size'] < 1 or $_FILES['mapfile']['size'] > 64000)
{
$errormessage = "There was an error with your upload. Please try again.";
}
This is the condition which is throwing the error. So based on this condition, You can check step-by-step
What is the value of $_FILES['mapfile']['error']
Is the map file which is getting upload is of type application/octet-stream or not
The uploading map file size
One of them is the reason for failing. If uploading file is a image file in png/jpeg format which image/png or image/jpeg rather then application/octet-stream, then it's better to add check for these two mime-types as well
Check if server file upload size is more than you are trying to upload !
You can check these settings in php.ini file

Strange PHP multiple file upload issue

Before you asked, I did look at all the similar topics and did not not find the solution to my problem. When I try to upload multiple files, say 4, 3 files are uploaded. I am really sure the loop is correct, but i could be wrong. Self-taught PHP newbie.
The code is as follows:
if(isset($_POST['submit']) && $_POST['submit']=="Upload"){
if(count($_FILES['image_filename']['name']) == 0)
{
$form->seterror("fileupload"," * At least one file required.");
}
if($form->num_errors == 0)
{
$directory="../../images/properties";
$ref='';
//Loop through each file
for($i=0; $i<count($_FILES['image_filename']['name']); $i++)
{
if($_FILES['image_filename']['name'][$i] != "")
{
//Get the temp file path
$filename = $_FILES['image_filename']['name'][$i]; // filename stores the value
$filename = str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
$filename = stripslashes($filename); // strip file_name of slashes
$filename = str_replace("'","",$filename); //remove quotes
$filesize = $_FILES['image_filename']['size'][$i];
$filetype = $_FILES['image_filename']['type'][$i];
$filetemp = $_FILES['image_filename']['tmp_name'][$i];
//echo $filename.'<br>';
$filework->file_upload($_FILES['image_filename']['name'][$i],$directory,$_FILES['image_filename']['tmp_name'][$i]); // this is my File upload class
$ref=$_FILES['image_filename']['name'][$i];
if($countImg == 0) {
if($i==0) {
$main='1';
} else {
$main='0';
}
} else {
$main='0';
}
$q="INSERT INTO property_images(property_id,image_filename,image_reference,main_image)".
" VALUES (".$_GET['pid'].",'".$_FILES['image_filename']['name'][$i]."','".$ref."','".$main."')";
//echo $q.'<br>';
$database->query($q) or die(mysql_error());
$x++;
}
}
}
}
[/code]
Isn't the loop skipping the last file?
Try changing this:
for($i=0; $i<count($_FILES['image_filename']['name']); $i++)
to:
for($i=0; $i<=count($_FILES['image_filename']['name']); $i++)

upload more than 200 images using php and html input tag

i'm trying upload multiple image files in php.i edited the php.ini and set upload_max_files to 20000.but it only uploads 200 images at one time.any help will be appriciated.
here's my code
if(isset($_FILES['files'])){ $count=0; foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name){
$target="upload/photo/";
$target=$target.$_FILES['files']['name'][$key];
$partphoto = substr("$target", 13, -4);
$qq="select * from idol_student_photo where name='$partphoto'";
$res=mysql_query($qq);
$row=mysql_fetch_array($res);
if(file_exists($target))
{
echo $_FILES['files']['name'][$key]." already exists in photo folder <br />";
}
else if($row['name'])
{
echo $partphoto." already exists database <br />";
}
else
{
if(move_uploaded_file($tmp_name, $target)){
//$id = mysql_insert_id($con);
mysql_query("INSERT INTO tablename VALUES ('$partphoto')");
$count=$count+1;
}
}
}
echo "<center>".$count."file uploaded</center>";
}
It's probably a PHP Limitation. So we can't really help you with that. However; most PHP system do have a zip function. So detect if there are too much pictures in you clientside validation and suggest using the zip method to a user. I haven't tested this code, but should put you in the right direction!
$zip = zip_open("/tmp/youruploaded.zip");
$target="upload/photo/";
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$zipfilename = zip_entry_name($zip_entry);
$target=$target.$zipfilename;
$partphoto = substr("$target", 13, -4);
$qq="select * from idol_student_photo where name='$partphoto'";
$res=mysql_query($qq);
$row=mysql_fetch_array($res);
if(file_exists($target)) {
echo $zipfilename." already exists in photo folder <br />";
} else if($row['name']) {
echo $zipfilename." already exists database <br />";
} else{
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
if (file_put_contents($target, $buf)) {
mysql_query("INSERT INTO tablename VALUES ('$partphoto')");
$count=$count+1;
} else {
echo 'can\'t put picture';
}
}
}
zip_close($zip);
}
Good luck

Multiple files upload with array name in CodeIgniter

i've problem with my code here.
The case is, i have multiple input file form, i need to get name of current array (which contain database id) and upload the file from it.
Here's in my views
foreach($result2 as $result3)
{
print "
<tr>
<td><input type=file name=baddismantling[".$result3['iddeployment']."] size=20></td>
</tr>
";
}
so, there'll be various of upload form and name too, but it always unique.
and after user click submit button, that form will call function in my controller, and here's
the function that handled it
private function _ready_to_start($sessiondata)
{
if($post['doSubmitDismantlingAction'] == 'uploadbad')
{
while ($fruit_name = current($_FILES['baddismantling']['name']))
{
if($fruit_name != false)
{
//GET ID FROM DEPLOYMENT DB
$deploymentid = key($_FILES['baddismantling']['name']);
$file = "baddismantling[$deploymentid]";
if(!$this->upload->do_upload($file))
{
$check3[] = $this->upload->display_errors()." target: ".$file;
}
$check2 = $this->upload->data();
}
next($_FILES['baddismantling']['name']);
}
//SHOW RESULT WHILE UPLOADING
print implode($check3);
}
}
as you see,i've successful with getting the
$deploymentid = 1
as i wish...but, browser give me :
You did not select a file to upload. target: baddismantling[1]
anyone can give me suggestion about that problem?or there's something wrong with my code?
as note :
there's no problem with configuration $this->upload-> because i've
successfull with a single upload form only
thanks for your time with my question, and i've "luckily" got my own solving from question above with this code :
$check3 = array();
$count = 0;
$check = ($_FILES == true ? count($_FILES['baddismantling']['name']) : (0));
while ($fruit_name = ($check == true && $check > 0 ? current($_FILES['baddismantling']['name']) : (false)) || $count <= $check){
$count++;
if($fruit_name == true && key($_FILES['baddismantling']['name']) == true)
{
$iddeployment = key($_FILES['baddismantling']['name']);
/*THIS PART WAS HELPING ME*/if($_FILES['baddismantling']['name'][$iddeployment] == true)
{
$_FILES['userfile']['name'] = $_FILES['baddismantling']['name'][$iddeployment];
$_FILES['userfile']['type'] = $_FILES['baddismantling']['type'][$iddeployment];
$_FILES['userfile']['tmp_name'] = $_FILES['baddismantling']['tmp_name'][$iddeployment];
$_FILES['userfile']['error'] = $_FILES['baddismantling']['error'][$iddeployment];
$_FILES['userfile']['size'] = $_FILES['baddismantling']['size'][$iddeployment];
if (!$this->upload->do_upload())
{
$check3[] = $this->upload->display_errors();
}
else
{
$uploaddata = $this->upload->data();
$result['badfilename'] = $uploaddata['full_path'];
$result['id'] = $iddeployment;
$sql = $this->sql->updatedismantlingBAD($result);
}
}
}
next($_FILES['baddismantling']['name']);}

A peculiar newbie debugging

It is one of the things I should have the know how but it really bugs. I have a large script which automates several tasks. It starts with uploading of files after which data from the files are extracted and then imported into mysql. In debugging mode it works perfectly but on my web front-end, execution stops after the data from the uploaded file is extracted. It never reaches the importation into database phase.
I realised that I had used this particular code below which I hold suspect:
$newFilePath = $upload_directory."/".$inFileName;
//opening the input file
if($inFileName != "")
$inputFile = fopen($newFilePath,"r");
else exit(1);
if(!$inputFile)
exit(0);
while(!feof($inputFile)) {
It is obvious that the exit() as used terminates the scripts thereby leaving out the lines that is handling the import of data into mysql.WIth the above, the upload works and the data separation carried out but the import never got executed. After some study I reviewed that portion by doing something quite appropriate like:
if (file_exists($inFileName)){
$inputFile = fopen($newFilePath,"r");
}
else {
echo "No file found ";
}
if (is_readable($inputFile)){
echo " ";
}else {
echo 'The file could not be read';
}
Now this piece of code review did not get me anyway as the upload is not even possible.
Now my problem is to fix this little portion of the code so I get the other parts of the script after it to do the import. It has been a nightmare for a beginner like me. I would appreciate if someone could review the above portion in a different way. I hope to see something that is similar or different but valid. I have learnt tougher stuff than this but this is simply nuts. I hope someone could understand my explanation. Thanks
New Edit.
if (is_array($inFilesArray)) {
foreach($inFilesArray as $inFileName) {
$numLines = 1;
$newFilePath = $upload_directory."/".$inFileName;
//opening the input file
if (file_exists($newFilePath)){
if (is_readable($newFilePath)){
$inputFile = fopen($newFilePath,"r");
}
} else {
echo "File not accessable";
}
//reading the inFile line by line and outputting the line if searchCriteria is met
while(!feof($inputFile)) {
$line = fgets($inputFile);
$lineTokens = explode(',',$line);
// Assign Device ID
switch ($lineTokens[0]){
case "IMEI 358998018395510\r\n":
$device_id = 1;
break;
case "IMEI 352924028650492\r\n":
$device_id = 3;
break;
case '$GPVTG':
$device_id = 2;
break;
}
if(in_array($lineTokens[0],$searchCriteria)) {
if (fwrite($outFile4, $device_id . "," .$line)===FALSE){
echo "Problem writing files\n";
}
$time = $lineTokens[1];
$date = $lineTokens[9];
$numLines++;
}
// Defining search criteria for $GPGGA
$lineTokens = explode(' ',$line);
$searchCriteria2 = array('OutCell');
if(in_array($lineTokens[0],$searchCriteria2)) {
if (fwrite($outFile5, $time.",".$date."\n")===FALSE){
echo "Problem writing to file\n";
}
}
}
fclose($inputFile);
}
Entire Script
<?php
#This script has threee parts: The first handles the uploaded files while the second part retrieves all RMCs and Handover dates and the 3rd handles importation of the data into their respective table in mysql database.
# This part uploads text files
include 'setamainfunctions.php';
if (isset($_POST['uploadfiles'])) {
$number_of_uploaded_files = 0;
$number_of_moved_files = 0;
$uploaded_files = array();
$upload_directory = dirname(__file__) . '/Uploads/';
//echo count($_FILES['uploadedFile']['name'])." uploaded ";
for ($i = 0; $i < count($_FILES['uploadedFile']['name']); $i++) {
//$number_of_file_fields++;
if ($_FILES['uploadedFile']['name'][$i] != '') { //check if file field empty or not
$number_of_uploaded_files++;
$uploaded_files[] = $_FILES['uploadedFile']['name'][$i];
//if (is_uploaded_file($_FILES['uploadedFile']['name'])){
if (move_uploaded_file($_FILES['uploadedFile']['tmp_name'][$i], $upload_directory . $_FILES['uploadedFile']['name'][$i])) {
$number_of_moved_files++;
}
}
}
echo "Number of files submitted $number_of_uploaded_files . <br/>";
echo "Number of successfully moved files $number_of_moved_files . <br/>";
echo "File Names are <br/>" . implode("<br/>", $uploaded_files)."\n";
echo "</br>";
echo "<p> Please find the processed RMCs and corresponding handovers as text files named:outputRMCs.txt and OutputHandovers.txt in the Setapro project root folder</p>";
/* echo "<br/>";
echo "<br/>";
echo "<p> Result of Mobile GPRMCs Transaction";
//echo "Total entries imported:.$numlines . <br/>";
echo "Data extraction and import mobile mobile GPRMCs successfuly completed";
echo "<br/>";
echo "<br/>";
echo "<p> Result of Handover Transaction";
//echo "Total entries imported:.$numlines . <br/>";
echo "Data extraction and imports for mobile handovers successfuly completed";*/
}
# This is the start of a script which accepts the uploaded into another array of it own for extraction of GPRMCs and handover dates.
$searchCriteria = array('$GPRMC');
//creating a reference for multiple text files in an array
/*if(isset($_FILES['uploadedFile']['name']))
$_FILES['uploadedFile'] = '';
}else {
echo "yes";
}*/
$inFilesArray = ($_FILES['uploadedFile']['name']);
//$inFiles = fopen($_FILES['uploadedFile']['tmp_name'], 'r');
//This opens a textfile for writing operation and puts all the entries from the multiple text files into one distinct textfile
if( ($outFile4 = fopen("outputRMCs.txt", "a")) === false ){
echo " ";
}
$outFile5 = fopen("outputHandovers.txt", "a");
//processing individual files in the array called $inFilesArray via foreach loop
if (is_array($inFilesArray)) {
foreach($inFilesArray as $inFileName) {
$numLines = 1;
$newFilePath = $upload_directory."/".$inFileName;
$correctFile = false;
//opening the input file
if (file_exists($newFilePath)){
if (is_readable($newFilePath)){
$inputFile = fopen($newFilePath,"r");
$correctFile = true;
}
}
if (!$correctFile)
echo "File not accessable";
//reading the inFile line by line and outputting the line if searchCriteria is met
while(!feof($inputFile)) {
$line = fgets($inputFile);
$lineTokens = explode(',',$line);
// Assign Device ID
switch ($lineTokens[0]){
case "IMEI 358998018395510\r\n":
$device_id = 1;
break;
case "IMEI 352924028650492\r\n":
$device_id = 3;
break;
case '$GPVTG':
$device_id = 2;
break;
}
if(in_array($lineTokens[0],$searchCriteria)) {
if (fwrite($outFile4, $device_id . "," .$line)===FALSE){
echo "Problem writing files\n";
}
$time = $lineTokens[1];
$date = $lineTokens[9];
$numLines++;
}
// Defining search criteria for $GPGGA
$lineTokens = explode(' ',$line);
$searchCriteria2 = array('OutCell');
if(in_array($lineTokens[0],$searchCriteria2)) {
if (fwrite($outFile5, $time.",".$date."\n")===FALSE){
echo "Problem writing to file\n";
}
}
}
fclose($inputFile);
}
//close the in files
fflush($outFile4);
fflush($outFile5);
}
fclose($outFile4);
fclose($outFile5);
#End of script for handling extraction
# This is the start of the script which imports the text file data into mysql database and does the necessary conversion.
$FilePath1 = $_SERVER["DOCUMENT_ROOT"] . '/setapro/outputRMCs.txt';
if (is_readable($FilePath1)) {
$handle = fopen($FilePath1, "r");
rmc_handoverHandler($handle);
echo "";
fclose($handle);
} else {
echo 'The file could not be read';
}
#Begining of script to handle imports into handover table
$FilePath2 = $_SERVER["DOCUMENT_ROOT"].'/setapro/outputHandovers.txt';
if (is_readable($FilePath2)) {
$handle = fopen($FilePath2, "r");
mobile_handoverHandler($handle);
echo "";
fclose($handle);
} else {
echo 'The file could not be read';
}
#End of script for handling imports into handover table
?>
It seems to me you want to do something more like this...
$newFilePath = $upload_directory."/".$inFileName;
$goodFile=false;
//Does the file exist?
if (file_exists($newFilePath)){
//If so, is it readable?
if (is_readable($newFilePath)){
//if it exists, and it readable, open it
$inputFile = file_get_contents($newFilePath);
//Don't display the error when done because file is good
$goodFile=true;
//Do Other stuff with file contents
}
}
if (!goodFile) echo "File Access Error";
You want to use newFilePath as it contains the path as well as the file name. The fact that you are checking for the file's existence and readability without also passing the file's path (only the file name) may be the cause of your issues.
UPDATE
try {
for ($i = 0; $i < count($_FILES['uploadedFile']['name']); $i++) {
//$number_of_file_fields++;
if ($_FILES['uploadedFile']['name'][$i] != '') {
$number_of_uploaded_files++;
$uploaded_files[] = $_FILES['uploadedFile']['name'][$i];
//if (is_uploaded_file($_FILES['uploadedFile']['name'])){
if (move_uploaded_file($_FILES['uploadedFile']['tmp_name'][$i], $upload_directory . $_FILES['uploadedFile']['name'][$i])) {
$number_of_moved_files++;
}
}
}
} catch (exception $e){
echo "General Error";
}

Categories