jeudi 29 mai 2014

$_FILES['fileToUpload']['name'] showing " Undefined index: fileToUpload" when using jquery mobile 1.4 but works without jquery


Vote count:

0




Im running an upload script so that the user can select an image then upload it to the database (I know this isn't best practise but I'm working with an existing database and this is the way it needs to work!). These scripts work perfectly when I don't have them in jquery mobile. The issue is that as soon as I try to use the code in my webapp I get the following error



Undefined index: fileToUpload



I have been having issues in the app with using <form method="post" and I'm wondering if this is likely to be the issue (which I think it is!) Does anyone know of a workround to do something similar using <form method="get"?


Please see code below:



<form enctype="multipart/form-data" method="post" action="upload.php">
<img src="http://ift.tt/1ePKnR9" width ='100px' height='100px'>
<div class="row">
<label for="fileToUpload">Select a File to Upload</label><br />
<input type="file" accept="image/*" name="fileToUpload" id="fileToUpload" capture="camera">
</div>
<div class="row">
<input type="submit" value="Upload" />
</div>


the php (have cut out some code to make it more readable!):



$custid='123456789';
$userid='user';
$date = date_create();

if ($_FILES['fileToUpload']['error'] > 0) {
echo "Error: " . $_FILES['fileToUpload']['error'] . "<br />";
} else {

$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');

$fileExtension = strrchr($_FILES['fileToUpload']['name'], ".");

if (in_array($fileExtension, $validExtensions)) {

$newName = time() . '_' . $_FILES['fileToUpload']['name'];
$destination = 'uploads/' . $newName;

if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $destination)) {
echo 'File ' .$newName. ' succesfully copied';

$image = file_get_contents ($destination);

$sqlcheck = "select id from blobstore where id='$custid'";
$result = sasql_query($connect, "$sqlcheck");

if (!isset($row['id'])){
//do the insert
}

else if (isset($row['id'])){
// do the insert again in another way
}
//delete file from uploads folder
unlink($destination);
}
} else {
echo 'You must upload an image...';
}
}


asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire