开发者

PHP upload problems

I'm am completely stumped. I'm trying to upload a simple photo via HTTPS. I've done this countless times, but this开发者_StackOverflow one time it's not working.

Here's the situation. I'm using a very simple yet robust file upload script, simple input=file, etc. and submit button to upload using POST, from there PHP takes over and does the rest. Once over on the php side I went through some problem solving/debugging and noticed that the file name was a bunch of goop... uploads/1.��8D��J��Q��9. certainly not the file i choose.

I'm not sure if this is a problem with the SSL, HTML5, or PHP. All other data passed through ends up very readable in the DB.

I've noticed something new in the file upload box of c:\fakepath, i've used HTML5 for the past several months and haven't seen this, looked it up and saw it's an HTML5 security feature. dont know if that's causing the problem or not?

Ok so I've verified with a friend (incase I was going crazy) that the HTML and PHP is fine.

I have even broken it down and went super simple with still no luck...

$uploaddir = 'uploads/';

$uploadfile = $uploaddir . basename($_FILES['photo']['name']);
$filename = $_FILES['photo']['name'];
if (move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile)) {
    echo "Alls good.";
}

Also on the HTML page I am using the jquery plugin "niceforms" I have turned this off to rule it out, and still does not work.

Thank you.


I am wondering whether you declared your from like the one below:

<form enctype="multipart/form-data" action="uploader.php" method="POST">
   <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
   Choose a file to upload: <input name="uploadedfile" type="file" /><br />
   <input type="submit" value="Upload File" />
</form>

You should declare the enctype if you upload something.


It's always the simple things isn't it? I think you may be overlooking the relative upload dir path that you are moving the file to. I wouldn't use a relative path here.

$uploaddir = 'uploads/';

Instead, try using the full file system path to the upload directory. This is usually the document root concatenated with your 'uploads' directory.

$_SERVER['DOCUMENT_ROOT'] or dirname(__FILE__)

...should help define the path.

$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/uploads/';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜