Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

From '/' to '//'

Status
Not open for further replies.

Geminist

Programmer
Jul 6, 2002
25
CN
Hi,need your help!
I'm making some uploading page with php.First I upload a file and store the file name in $sfile as "c:\winnt\phptmp2BA.tmp".It is posted to itself and $sfile is a hidden input.
But the seconde time I use it to upload another file,find that $sfile is changed to "c:\\winnt\\phptmp2BA.tmp".It cause an error with copy().
I don't konw what's the problem.
 
I think you can use / instead of \\ with copy. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
I use copy($sfile,$sfile1).$file1 is made up of my default file path and $file_name(the system variable in uploading).
Because $sfile is changed to "C:\\winnt\\phptmp2BA.tmp",it causes an error.I just don't know why the $sfile changes just through "post".
 
To find out what serverside variables are in use that you can use instead of sending them yourself:
(version dependant so one OR the other should work for you:
echo "FILES:";
print_r($_FILES);
echo &quot;<hr><br>HTTP_POST_FILES:&quot;;
print_r($HTTP_POST_FILES);

put both lines above your copy() statement and see which variable holds the info you need.

You should get a keyed array like array(1=>filename2=>tmpname 3=>size ....

then use
copy($_FILES[tmp_name],$_FILES[filename]);
or the HTTP_POST_FILES equivalent. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hello Geminist ,

When u copy a file first time on server in hardcoded path u need to escape backslash (ie '\' by '\\')

so ur copy command will be something like

copy ($sfile,&quot;c:\\winnt\\phptmp2BA.tmp&quot;) ;

Hope that will help u

cheers

spookie


 
I did a test and find that every string containing '\' changes to '\\' after post.Can you show me how to solve the problem?
 
$string_with_no_slashes=stripslashes($string);
echo $string_with_no_slashes; ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
It works,but it also changes &quot;C:\winnt\phptmp2A3.tmp&quot; to &quot;C:winntphptmp2A3.tmp&quot;.
Is there any other way?
Can I get the string with '\' unchanged through post?
 
so you want to send a variable to the sevrer like
$variable=&quot;c:\winnt\phptmp2A3.tmp&quot;

but why? when you upload a file the server knows teh uploaded file by a different name.

still

$varible=&quot;c:/winnt/phptmp2A3.tmp&quot;;

I still don't get why you want to send a path to it tho.

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top