This is a discussion on Strange Upload Problem within the PHP Language forums, part of the PHP Programming Forums category; I am creating a php script that I can call from a delphi program, this itself is easy as I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I am creating a php script that I can call from a delphi program, this
itself is easy as I have already done this. The problem lies within the php script, here is the code that DOESN'T work: <? $temp = $_POST['userid']; $uppath = "users/$temp"; clearstatcache(); if(file_exists($uppath)){ unlink($uppath); } if(copy($imgname, $uppath)){ print("done_upload"); }else{ print("failed_upload"); } ?> KEY: userid will be something like '5.jpg' without quotes, so uppath will be something like 'users/5.jpg'. This is the error responce from the script, sorry its in a raw state: <br /> <b>Warning</b>: copy(users/5.jpg ): failed to open stream: Invalid argument in <b>C:\Program Files\Apache Group\Apache2\htdocs\messenger\up.php</b> on line <b>8</b><br /> failed_upload NOW, if I hardcode the uppath to 'users/5.jpg' NOT using userid to complete the path this works - Weird, example below: <? //$temp = $_POST['userid']; $uppath = "users/5.jpg"; clearstatcache(); if(file_exists($uppath)){ unlink($uppath); } if(copy($imgname, $uppath)){ print("done_upload"); }else{ print("failed_upload"); } ?> I can't understand why I can hardcode the path, which is the same as the one made up using the userid, and it works perfect. The path I make using userid when printed out is correct and the file exists cos I have checked this using a file_exists() check. Any help is appreciated Thanks Ian |
|
|||
|
Ian Hardcastle wrote:
> I am creating a php script that I can call from a delphi program, this > itself is easy as I have already done this. The problem lies within > the php script, here is the code that DOESN'T work: > ><? > $temp = $_POST['userid']; Maybe there's some extra characters in the POST variable $temp = trim($temp); > $uppath = "users/$temp"; [snip] -- --= my mail box only accepts =-- --= Content-Type: text/plain =-- --= Size below 10001 bytes =-- |
|
|||
|
Thanks Pedro the trim() function seemed to fix the problem. There must
have been some invalid characters or blank space that didn't show up when output so the comparison looked the same. Thanks again, if only all problems were as simple to fix. Later |