English 中文(简体)
采用移动-上载-文件()帮助向服务器上载成像
原标题:uploading img to server using move_uploaded_file() help
  • 时间:2011-10-19 21:22:47
  •  标签:
  • php

因此,在这里试图学习更多的实验室,并......试图增加一个用户通过移动向服务器上载(an)的形象,即:上载——file...oh和现在装在WAMP上。

the book im reading ...long story short, the example shown doesnt work. Ive Googled around and literally copy pasted a few relavant examples ive found and still....well to be clear, be it that i wrote it or from the net, i can upload the image name (along with other values) to tables on the db i have set up but the image itself doesn t move to the directory I ve set up for it.

我把我的所有手法都删除到简单的桌子上,而简单地把他放在别处,以确保任何东西都不相冲突,而且仍然 n。

我是:

<form method="post" action="testUpload.php" enctype="multipart/form-data">

<input type="hidden" name="MAX_FILE_SIZE" value="32768" >

<table summary="guitarwars lesson" width="500">
        <tr>
            <td>load picture:</td>
            <td><input type="file" name="screenshot" id="screenshot" ></td>
        </tr>
        <tr>
            <td><input type="submit" name="submit" action="submit"></td>
        </tr>
</table>


</form>

这里是我的营地:

<?php 

$screenshot = $_FILES[ screenshot ][ name ];
//$destination = "images/user_avatars/$screenshot";
$insertValues = "INSERT INTO testdb(screenshot) VALUES ( $screenshot )";


//---declare connection.
$connect2db = mysqli_connect( 127.0.0.1 , root , pass , dbname );
if(!$connect2db){
    die("Sorry but theres a connection to database error" . mysqli_error);
} else {

    //pg intro mssg
    echo   <span style="font-size:25px; color:green;"> --- Link Established with Database ---.<span/><br/><br/> ;   
}


// put into db.
if(!empty($screenshot)) {
    $insertData = mysqli_query($connect2db, $insertValues);
    echo  data submitted. thank you ;

        move_uploaded_file ($_FILES[ screenshot ][ tmp_name ],"images/user_avatars/{$screenshot}");


        echo  IMAGE UPLOAD COMPLETE ;

}
mysqli_close($connect2db);
?>

now i dont get an error...i actually get the echo "image upload complete" part... and like i said, with the app code, i get multiple values AND the image name going through and being saved onto the db, but the image itself being moved from temp to my location is a no go.

any tips links, etc i gladly appreciate. Thank you in advance.

最佳回答

If that s code from your book, then throw the book out and burn it as fast as you can.

a) http://bobby-tables.com” rel=“nofollow” 任何象样的PHP辅导,如果《裁武条约》有减少注射战略,那么如何处理数据库。

b) 您的链接错误使用mysqli_error,这是一个未界定的不变。 您或许希望mysqli_error(,这是一项职能呼吁。

c) 该代码假定有效完成上载。 卸载量在帽子下时可能/会失败,因此,NOT检查错误是通往理发的快路。 至少在文字上应该有类似的东西。

if ($_FILES[ screenshot ][ error ] !== UPLOAD_ERR_OK) {
   die("Upload failed with error code " . $_FILES[ screenshot ][ error ]);
}

这些错误代码为here

d) 您的代码正在使用用户提供的文件名称,将文件存放在地上。 没有任何规定说,恶意使用者可以把档案名称贴上黑板,以包括路径信息,因此,你的代码实际上允许新用户在互联网服务器上打上笔记,而网站服务器程序可以读取。 页: 1

e) Your code also assumes the file move succeeded, without checking for errors. It should have at mininum

$status = move_uploaded_file(...);
if (!$status) {
     die("Move failed!");
}

或类似情况。

f) 您的代码假定,所有数据库查询都成功。 即便是你的询问(见上文(a)项)完全形成100%,由于任何其他原因,询问也可能失败。 仅用微金:

$result = mysql_query(...) or die(mysqli_error());
问题回答

作为开端,你可以补充一点。

 if(!move_uploaded_file(...))
  die( error );

页: 1

move_uploaded_file ($_FILES[ screenshot ][ tmp_name ],"images/user_avatars/{$screenshot}");


    echo  IMAGE UPLOAD COMPLETE ;

iii

if (move_uploaded_file ($_FILES[ screenshot ][ tmp_name ],"images/user_avatars/{$screenshot}")) {
    echo  IMAGE UPLOAD COMPLETE ;
}

如果成功的话,你会回响。

提供绝对道路:

move_uploaded_file ($_FILES[ screenshot ][ tmp_name ],"/path/to/images/user_avatars/{$screenshot}");




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签