Results 1 to 6 of 6

Thread: Ajax values with form, and called variables in PHP

  1. #1
    Join Date
    Jun 2013

    Ajax values with form, and called variables in PHP

    Hi, I cannot fathom for the life of me what is wrong with my code. In any case, I believe the ajax code is right (I could be wrong though).

    I have a "form" which is one field long and which I don't care about submitting. I need to use the CURRENT typed in value, so that I can send it over to another page without submitting any values and thus changing page - hence the use of ajax. I have a fake submit button (created by divs) which is outside of the form. I will use that one to submit the content along with the folder name.

    On the second page, which is an upload page, I am trying to create a folder. Basically, in my images folder, I want to create ONE subfolder only. So in my form, the person types in a name in the text box, and then that value is going to become the name of the new folder.

    I looked on the net concerning something called folder recursion. Someone suggested something about that (but I had misunderstood his suggestion). Anyhow, I have looked online for that to begin with, but without any luck. As I need to use typed in values, what I found online does not help me in that regards.

    The best I can output is $folder which is created in my images directory. In any case, since that attempt has failed, I have reworked my coding several times. But the following is the best I can come up with.

    Here is my coding:

    HTML Code:
        <meta charset="utf-8">
        <title>File Upload!</title>
        <script src="jquery.js"></script>
        <script src="javascript.js"></script>
        <link rel="stylesheet" type="text/css" href="style.css" />
        <link rel="stylesheet" type="text/css" href="pacifico.css" />
                    value: $("#folder").val()
        }, 2000);
            	<input type="text" id="folder" name="folder">
                <input id="btn_send" type="button" value="Submit" />
        <div class="content">
        	<div id="drop-files" ondragover="return false">
        		Drop Images Here
        	<div id="uploaded-holder">
        		<div id="dropped-files">
        			<div id="upload-button">
        				<a href="#" class="upload">Upload!</a>
        				<a href="#" class="delete">delete</a>
        				<span>0 Files</span>
        		<div id="extra-files">
        			<div class="number">
        			<div id="file-list">
        	<div id="loading">
        		<div id="loading-bar">
        			<div class="loading-color"> </div>
        		<div id="loading-content">Uploading file.jpg</div>
        	<div id="file-name-holder">
        		<ul id="uploaded-files">
        			<h1>Uploaded Files</h1>
    and the other page

    PHP Code:
    $_GET['folder'] . '/';
    $dirPath $folder;
    $result mkdir($dirPath0755);
        if (
    $result == 1) {
    $dirPath " has been created";
        } else {
    $dirPath " has NOT been created";
    // We're putting all our files in a directory called images.
    $uploaddir 'images/'.'$folder';
    // The posted data, for reference
    $file $_POST['value'];
    $name $_POST['name'];
    // Get the mime
    $getMime explode('.'$name);
    $mime end($getMime);
    // Separate out the data
    $data explode(','$file);
    // Encode it correctly
    $encodedData str_replace(' ','+',$data[1]);
    $decodedData base64_decode($encodedData);
    file_put_contents($uploaddir.$folder.$name$decodedData)) {
        else {
    // Show an error message should something go wrong.
    echo "Something went wrong. Check that the file isn't corrupted";

  2. #2
    Join Date
    Jul 2013
    Voorheesville NY USA
    Are you sure that you ajax-called script does what you want it to do? I always debug these by running them directly and then calling them via ajax when I know they work.

    PS - You're running the mkdir on the folder name that you accept from the url. but then you are doing the file upload to a folder that begins with "images/". Is that what you want? Unless this script itself exists in the images folder.

    Also - you seem to be collecting inputs from a GET array and a POST array. I've never done an ajax using jquery - is that possible? It's not (that I know of) with pure JS.

  3. #3
    Join Date
    Jun 2013
    Uhm, I think so. I see it running on the console. But I'm not that good at knowing what it does. I do know that whenever I type in something, there is a number that changes on the console when ajax refreshes.

    Wait, are you saying that I need to run the script INSIDE my images folder?? -_- If that is the case...
    Although yes, I do expect for it to create a folder inside the images directory. I can do either by itself (creating a directory or uploading a file, but just not by itself).

    A for the GET function, forget about that. It's actually POST. I was trying different things, but forgot to change it back. I think you can using jquery, since I'm using PHP, no? Also, it originates from html coding, and then goes with PHP.

  4. #4
    Join Date
    Jul 2013
    Voorheesville NY USA
    I was suggesting running the ajax called php by itself - directly. Just to see the echos come back with the right info.

    As for your folder creation - it appears that you create a folder called "(user input)" and then attempt to upload a file to "images/(user input)". Those are two different folders UNLESS the script that is doing it is actually stored in the images folder, which is not normally where it should be (IMHO).

    As for the GET/POST confusion - it is not good practice to post outdated code online for us to help you debug. You should at least give us the same code that you are working with otherwise we could be wasting our time trying to help you.

  5. #5
    Join Date
    Jun 2013
    What do you mean by running the ajax via PHP? How could I echo this?
    			var folder = $('#folder').val();
    			$.post('upload.php', {folder:folder}, function(data){
    			  console.log(data + 'saved!');
    Or rather, what parts would you echo? Considering that this is in my html, I am confused about what you mean. Pardon my ignorance in this matter.

    I copied the files inside the images folder, but to no avail.
    Concerning the GET and POST, I only remodified it much later actually (not right after). Sorry about that.

  6. #6
    Join Date
    Jul 2013
    Voorheesville NY USA
    Looking at your script it is jquery - at least it looks like it to me. I'm not even sure when it runs. Anyway - it is calling a script "upload.php" using a post method. I would modify that script to read REQUEST vars instead of POST ones, and execute the "upload.php" with GET parms to test it out thoroughly. THEN, I would go back to working out the kinks in the script that has your html in it.

    BTW - can you explain to me how this script works? Since I don't know jquery at all. IT does however appear to me that you are setting a timer to check if the button has been clicked every two seconds. Seems kind of wasteful to me. Why not just call the jquery logic from an 'onclick' event on your button and do away with the repeating check every two seconds? If I'm write in my guess that is.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14445 seconds
  • Memory Usage 2,935KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_code
  • (1)bbcode_html
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates