Jump to content

mahenda

Members
  • Posts

    146
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

mahenda's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. I have a form on which the filepond plugin send the file manually and it generate the base64 formated data of that file, unfortunately Icant get it's previous name so i randomize the name, and put the file directry in the final folder, is there any problem on security?, can i validate if its an image with all property such as size,dimension e.t.c Before adding it the directory? and how to get the it's new name to database. Look here if(empty($_POST['image'])) { echo 'add file!'; } $myimage = $_POST['image']; $myimage = str_replace('data:image/png;base64,', '', $myimage); $myimage = str_replace(' ', '+', $myimage); $decode = base64_decode($myimage); $myfile = $_SERVER['DOCUMENT_ROOT'].'/mages/' . uniqid() . '.png'; //now put the file file_put_contents($myfile, $decode);
  2. /*I'm trying to use dropzone js plugin for drag/drop single phote but it require me to create another form for file upload, but i want to use single form for both image and name input, i have no idea on how to combine this field in sinle request, the form to submit both image and name look like*/ <form method="POST" enctype="multipart/form-data"> <input type="text" name="name" id="name"> <!--how to replace this field with dropzone but in this form in order to use the same ajax as below--> <input type="file" name="photo" id="photo"> <button type="submit">send</button> </form> //ajax, how to add dropzone data in $("form").on('submit', function(e) { $.ajax({ url: 'add.php', type: 'POST', data: new FormData(this), dataType: 'JSON', contentType: false, cache: false, processData:false, }).done( function (data) { if(data.success == false) { //for error message response if(data.errors.name) { $('#name').append('<span class="text-danger">' + data.errors.name + '</span>'); } if(data.errors.photo) { $('#photo').append('<span class="text-danger">' + data.errors.photo + '</span>'); } } }); e.preventDefault(); });
  3. I face this issue, the file that needs to be uploaded is the one that does not exceed 100kb. The strange thing is that when I upload a file larger than 2MB error message not showing. While those below 2MB but grater than 100KB the error are shown, why
  4. access to image folder $uploads_dir = $_SERVER['DOCUMENT_ROOT'].'/yourapp/image_folder/';
  5. //i changed it like this and it works, the submit button look like <button type="submit"> $("form").on('submit', function(e) { $.ajax({ url: 'add.php', type: 'POST', data: new FormData(this), dataType: 'JSON', contentType: false, cache: false, processData:false, }).done( function (data) { // this return undrfined if(data.success == false) { if(data.errors.emptyphoto) { $('input').append('<span class="text-danger">' + data.errors.emptyphoto + '</span>'); } } }); e.preventDefault(); }); //but i have another issue here //my php.ini upload_max_filesize=2M post_max_size=8M //my new photo validation $ext = array('png', 'PNG'); if (in_array(pathinfo($_FILES['photo']['name'], PATHINFO_EXTENSION), $ext) && ($_FILES['photo']['size'] > 102400)) { $errors['image'] = "image greater than 100kb not allowed!"; } /*But when I upload images larger than 2M they enter the server as usual while those that are larger than 100kb and less than 2M do not enter at the same time they enter those with size less than 100kb. How can I only allow less than 100kb to be uploaded to a server*/
  6. I have found that when I use formdata api I do not have to enter dataType: 'JSON', and if I enter, it return undefined. now how do i get those error messages in php script since formdata api does not support JSON look $("#uploaad").click( function(e) { var formData = $(form).serialize(); $.ajax({ url: 'add.php', type: 'POST', data: formData, }).done( function (data) { // this return undrfined if(data.success == false) { if(data.errors.emptyphoto) { $('input').append('<span class="text-danger">' + data.errors.emptyphoto + '</span>'); } } }); e.preventDefault(); }); //and this return an error message as usually even if imagr name is available in the form field $("#uploaad").click( function(e) { var formData = $(form).serialize(); $.ajax({ url: 'add.php', type: 'POST', data: formData, dataType: "JSON", }).done( function (data) { if(data.success == false) { if(data.errors.emptyphoto) { $('input').append('<span class="text-danger">' + data.errors.emptyphoto + '</span>'); } } }); e.preventDefault(); });
  7. It actually sends the file name, and the php script above used to check if the file name does not exist then it will return the message in the above array. Surprisingly, when you upload a file it means that the file name is there and that message in the array is still coming back
  8. In short, The problem, I 'm facing here is why the error message appear even if i put an image
  9. it give the same issue, please refer to my ajax
  10. MY ajax look like, $("#uploaad").click( function(e) { $.ajax({ url: 'add.php', type: 'POST', data: {photo: $('#photo').val()}, dataType: "JSON", encode: true, }).done( function (data) { if(data.success == false) { if(data.errors.emptyphoto) { $('input').append('<span class="text-danger">' + data.errors.emptyphoto + '</span>'); } } }); e.preventDefault(); });
  11. ///i have field like this <form method="POST" enctype="multipart/form-data"> <input type="file" name="photo" id="photo"> <button type="button" id="uploaad">upload</button> </form> //my php code <?php //validation code $errors=[]; $data=[]; //The Error not appearing at first, but when I submit an empty field the error appear that is good, the problem start here, even if image is selected the error still appearing why not disappearing if(empty($_FILES["photo"]["name"])) { $errors['emptyphoto'] = 'please upload photo!'; } if(count($errors) !== 0) { $data['errors'] = $errors; } echo json_encode($data); ?>
  12. i have field like this <form method="POST" enctype="multipart/form-data"> <input type="file" name="photo" id="photo"> <button type="button" id="uploaad">upload</button> </form> <pre> <?php //my validation code $errors=[]; $data=[]; if(empty($_FILES["photo"]["name"])) { $errors['emptyphoto'] = 'please upload photo!'; } if(count($errors) !== 0) { $data['errors'] = $errors; } echo json_encode($data); ?> </pre> The Error appearing not at first, but when I submit an empty field the error appear, again even if image is selected the error still appearing why not disappearing
  13. How can i play with these role in my database table as you can see here //I have a database table CREATE TABLE users ( id int(10) NOT NULL PRIMARY KEY AUTO_INCREMENT, urole varchar(10) ); in the role column, I have 2 roles first role is only used once but the sound one can be assigned to more than one user, now I want to check my table if the first role is already registered, then we can't register user with that role, also the second role can exist two or more times //check role, a variable user role has been defined as $urole = $_POST['urole']; $check = $connect -> prepare('SELECT * FROM users WHERE urole = ?'); $check -> execute([$urole]); $checkfetch = $check -> fetch(); //I'm stacking here, I want to put $checkfetch['urole'] in rowCount() to be counted but I think this is not a correct way of using rowCount() if(($checkfetch['urole'] == 'MainAdmin') && ($checkfetch ->rowCount() == 1)) { echo 'This role can be used by only once!'; } //another role if(($checkfetch['urole'] == 'NormalAdmin') && ($checkfetch ->rowCount() < 4)) { echo 'This role can be used 4 times only!'; }
×
×
  • 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.