Full source code website bán hàng thương mại điện tử gần giống shopee
467.188 lượt xem;
1 <?php
2 include 'resize.php';
3
4 // Define a destination
5 $targetFolder = 'uploads'; // Relative to the root
6
7
8 if (!empty($_FILES)) {
9 date_default_timezone_set('UTC');
10 $tmp=getdate();
11 $tempFile = $_FILES['file']['tmp_name'];
12 $targetPath = dirname(__FILE__) . '/' . $targetFolder;
13 $imgFile = rtrim($targetPath,'/') .'/'.'img'.'/'. $tmp[0].$_FILES['file']['name'];
14 $thumbFile = rtrim($targetPath,'/') .'/'.'thumb'.'/'.$tmp[0]. $_FILES['file']['name'];
15
16
17 // Validate the file type
18 $fileTypes = array('jpg','JPG','jpeg','JPEG','gif','GIF','png','PNG'); // File extensions
19 $fileParts = pathinfo($_FILES['file']['name']);
20
21 if (in_array($fileParts['extension'],$fileTypes)) {
22 $image = new SimpleImage();
23 $image->load($tempFile);
24 $image->resizeToWidth(400);
25 $image->save($imgFile);
26 $image->load($tempFile);
27 $image->resizeToWidth(150);
28 $image->save($thumbFile);
29 //move_uploaded_file($tempFile,$imgFile);
30 //move_uploaded_file($tempFile,$thumbFile);
31
32 // $rs=array()
33 echo json_encode(array('rs'=>1,'thumb'=>$targetFolder.'/thumb/'.$tmp[0].$_FILES['file']['name'],'img'=>$tmp[0].$_FILES['file']['name']));
34 } else {
35 echo json_encode(array('rs'=>0,'msg'=>'Invalid file type.'));
36 }
37 }
38 ?>
2 include 'resize.php';
3
4 // Define a destination
5 $targetFolder = 'uploads'; // Relative to the root
6
7
8 if (!empty($_FILES)) {
9 date_default_timezone_set('UTC');
10 $tmp=getdate();
11 $tempFile = $_FILES['file']['tmp_name'];
12 $targetPath = dirname(__FILE__) . '/' . $targetFolder;
13 $imgFile = rtrim($targetPath,'/') .'/'.'img'.'/'. $tmp[0].$_FILES['file']['name'];
14 $thumbFile = rtrim($targetPath,'/') .'/'.'thumb'.'/'.$tmp[0]. $_FILES['file']['name'];
15
16
17 // Validate the file type
18 $fileTypes = array('jpg','JPG','jpeg','JPEG','gif','GIF','png','PNG'); // File extensions
19 $fileParts = pathinfo($_FILES['file']['name']);
20
21 if (in_array($fileParts['extension'],$fileTypes)) {
22 $image = new SimpleImage();
23 $image->load($tempFile);
24 $image->resizeToWidth(400);
25 $image->save($imgFile);
26 $image->load($tempFile);
27 $image->resizeToWidth(150);
28 $image->save($thumbFile);
29 //move_uploaded_file($tempFile,$imgFile);
30 //move_uploaded_file($tempFile,$thumbFile);
31
32 // $rs=array()
33 echo json_encode(array('rs'=>1,'thumb'=>$targetFolder.'/thumb/'.$tmp[0].$_FILES['file']['name'],'img'=>$tmp[0].$_FILES['file']['name']));
34 } else {
35 echo json_encode(array('rs'=>0,'msg'=>'Invalid file type.'));
36 }
37 }
38 ?>