Uploading JSON with js/php
-
I am trying to get the full path of an uploaded file. The php code is like this:
<span class="syntaxhtml"><br /><br /><span class="syntaxdefault"><?php<br /> $destination_path </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> getcwd</span><span class="syntaxkeyword">()</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> DIRECTORY_SEPARATOR</span><span class="syntaxkeyword">;<br /><br /></span><span class="syntaxdefault"> $result </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 0</span><span class="syntaxkeyword">;<br /></span><span class="syntaxdefault"> <br /> $target_path </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> $destination_path </span><span class="syntaxkeyword">.</span><span class="syntaxdefault"> basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> $_FILES</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'thefile'</span><span class="syntaxkeyword">][</span><span class="syntaxstring">'name'</span><span class="syntaxkeyword">]);<br /></span><span class="syntaxdefault"> <br /> if</span><span class="syntaxkeyword">(@</span><span class="syntaxdefault">move_uploaded_file</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$_FILES</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'thefile'</span><span class="syntaxkeyword">][</span><span class="syntaxstring">'tmp_name'</span><span class="syntaxkeyword">],</span><span class="syntaxdefault"> $target_path</span><span class="syntaxkeyword">))</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{<br /></span><span class="syntaxdefault"> $result </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> 1</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> <br /> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> <br /> ?><br /></span><script language="javascript" type="text/javascript"><br /> //d = '<span class="syntaxdefault"><?php echo basename</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> $_FILES</span><span class="syntaxkeyword">[</span><span class="syntaxstring">'thefile'</span><span class="syntaxkeyword">][</span><span class="syntaxstring">'name'</span><span class="syntaxkeyword">]);</span><span class="syntaxdefault"> ?></span>';<br /> d = '<span class="syntaxdefault"><?php echo $target_path</span><span class="syntaxkeyword">;</span><span class="syntaxdefault"> ?></span>';<br /> window.top.window.phpUpload(d);<br /></script> <br /><br /></span>
The rem'd out line gives me the filename OK, but the full path gives this alert in the js function - no slashes and the initial letter 'n' of the filename is missing ...
-
What does the alert say?
What does the full path string look like? -
@thomthom said:
What does the alert say?
What does the full path string look like?Sorry the attachment didn't get attached. Here it is ... off to bed
-
The answer from Stack Overflow is:
<span class="syntaxhtml">d = <span class="syntaxdefault"><?php </span><span class="syntaxkeyword">echo </span><span class="syntaxdefault">json_encode</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">$target_path</span><span class="syntaxkeyword">); </span><span class="syntaxdefault">?></span>;</span>
They pointed out this is only useful if you are working with localhost.
Advertisement