Home > Article > Backend Development > [Code] Simple implementation of uploading images in PHP_PHP tutorial
The following program uses the move_uploaded_file function to upload pictures to the program directory. The pictures are prefixed with temp_.
The following is a code snippet:
以下是代码片段:
(做为现在的主流开发语言)
if($_GET[’action’] == ’upfile’)
{
$target_path = ’temp_’.$_FILES[’photo’][’name’];
echo ’上传的临时文件:’ .$_FILES[’photo’][’tmp_name’] . ’
’;
echo ’上传的目标文件:’ .$target_path . ’
’;
echo $_SERVER["SCRIPT_FILENAME"] . ’
’;
echo $_SERVER["OS"] . ’
’;
//测试函数: move_uploaded_file
//也可以用函数:copy
move_uploaded_file($_FILES[’photo’][’tmp_name’], $target_path);
echo "Upload result:";
if(file_exists($target_path)) {
if($_SERVER["OS"]!="Windows_NT"){
@chmod($target_path,0604);
}
echo ’Succeed!
’;
} else {
echo ’Failed!’;
}
exit;
}
?> Registration
(as the current mainstream development language)
if($_GET['action'] == 'upfile')
{
$target_path = 'temp_'.$_FILES['photo']['name'];
echo 'Uploaded temporary file:' .$_FILES['photo ']['tmp_name'] . '
';
echo 'Uploaded target file:' .$target_path . '
';
echo $_SERVER["SCRIPT_FILENAME "] . '
';
echo $_SERVER["OS"] . '
';
//Test function: move_uploaded_file
//Can also be used Function: copy
move_uploaded_file($_FILES['photo']['tmp_name'], $target_path);
echo "Upload result:";
if(file_exists($target_path)) {
if($_SERVER["OS"]!="Windows_NT"){
@chmod($target_path,0604);
}
echo 'Succeed!< ;/font>
';
} else {
echo 'Failed!';
}
exit;
}
?> Registration
Technical exchanges never end
The following program uses the move_uploaded_file function to upload pictures to the program directory, and the pictures are prefixed with temp_. The following is a code snippet: html head titlephp (as the current mainstream development language...