0

I have such an upload form:

<form id="ajax-contact-form" action=""  method="post" enctype="multipart/form-data" name="form1">

    <INPUT type="text" name="name" value="Material Name:" onBlur="if(this.value=='') this.value='Material Name:'" 
                            onFocus="if(this.value =='Material Name:' ) this.value=''">
    <div class="clear"></div>
    Choose a file to upload<br />

<!--APC hidden field-->
    <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
    <div class="clear"></div>
<!---->

    <input name="file" type="file" id="file" />
    <div class="clear"></div>
<!--Include the iframe-->
    <br />
    <iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
    <br />
<!---->

    <INPUT class="submit" type="submit" name="submit" value="submit">
                  <div class="clear"></div>
  </form>

I'm using php, and I have to fetch directory name of the uploaded file to use in azure.

How can I manage this?

Thanks.

2
  • 1
    When you say, "fetch the directory name", do you mean getting the temporary directory that the file is uploaded to? Commented Jun 4, 2014 at 16:10
  • Sorry for being late Wes Rice, I couldn't see your comment at the time because of failure of the internet connection. Actually Wes Rice, I have to give a directory to upload a blob into a storage in Windows Azure like this, $content = fopen("c:\myfile.txt", "r"); $blob_name = "myblob";, so it doesn't matter which one, if it'S useful. If Azure will upload the file from the temporary directory, it will be okay as well. :) Commented Jun 4, 2014 at 17:00

1 Answer 1

2

If you are not using a framework, you could use the global $_FILES when processing the form. That will be an array of each of the files you form submitted, using the "name" of the input as key (which in your sample form is missing).

Inside that key, you'll find "name", "type", "tmp_name", "error" and "size".

tmp_name will have the absolute path to the temporary file stored on your server. The rest is self explanatory.

Now, if you are using a framework to process the form, most frameworks have an easier and error-proof way of fetching files from the request.

Update

$_FILES['file']['tmp_name'] will have the absolute path on your server to the uploaded file. With that, you can do file_get_contents() or whatever you like.

$_FILES['file']['name'] wil have the name of the file, in case you need to persist it somewhere.

If you are using a debugger such as xdebug, you could set a breakpoint, and look at the global yourself to get a better idea. If not, you can always do a var_dump($_FILES); in order to view the structure and get a sense of what is happening on the server.

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry for being late Martin Peverelli, I couldn't see your comment at the time because of failure of the internet connection. So can you show how can I use it in my algorithm? :)
Thank you Martin, actually I've solved the problem by uploading the file into the server at first, than uplaoding to the zure storage from web server. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.