Home  >  Article  >  Backend Development  >  [Code] Simple implementation of uploading images in PHP_PHP tutorial

[Code] Simple implementation of uploading images in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:30:42789browse

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:
以下是代码片段:
 
 
php<font class="reblank">(做为现在的主流开发语言)</font>上传图片简单实现 www.cncms.com.cn 
 
 
(做为现在的主流开发语言)
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

 
 
 
Your information 
     
  • Your Phot
  •  
 
 
 
 
 



php<font class="reblank">(as the current mainstream development language)</font>Easy implementation of uploading images www.cncms.com.cn


(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




Your information

  • Your Phot





Technical exchanges never end

http://www.bkjia.com/PHPjc/509156.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/509156.htmlTechArticle
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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn