我有一个表格,其中有一个名为'foto'的输入类型文件
目标是在进入数据库之前调整用户上传的照片。
主要错误是,当我点击提交时,页面显示了大量奇怪的代码:
����JFIF��m���b~bs�I$��'$V�ڳ�v,HL���rr0{ �r�I4����nCT�����O���%�vw|��;��[쯧��!VOݓI&Ҽ�M춶��o�Z�ѥ��Vb���������� ۧ��b��zi8Pr�%�9 ��猞3!�Dx�,U�8t�F�cМ�X��lP�
如果我点击提交,请执行以下说明
$fFoto="";
if($_FILES['foto']['error'] == UPLOAD_ERR_OK) {
$fFile="/upload/inserzionisti/".$id."_".$_FILES["foto"]["name"];
$fFoto=$id."_".$_FILES["foto"]["name"];
$percent = 0.5;
list($width,$height) = getimagesize("upload/inserzionisti/".$fFoto."");
$new_width = $width * $percent;
$new_height = $height * $percent;
$image_p = imagecreatetruecolor($new_width,$new_height);
$image = imagecreatefromjpeg("upload/inserzionisti/".$fFoto."");
imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height);
imagejpeg($image_p,null,100);
move_uploaded_file($_FILES["foto"]["tmp_name"],".".$fFile);
$sql = "UPDATE inserzionisti SET FotoUrl ='$fFoto' where Id=$id";
你有什么建议吗?
由于
答案 0 :(得分:0)
试试这段代码:
$fFoto="";
if($_FILES['foto']['error'] == UPLOAD_ERR_OK) {
$fFile="/upload/inserzionisti/".$id."_".$_FILES["foto"]["name"];
$fFoto=$id."_".$_FILES["foto"]["name"];
$percent = 0.5;
list($width,$height) = getimagesize("upload/inserzionisti/".$fFoto."");
$new_width = $width * $percent;
$new_height = $height * $percent;
$image_p = imagecreatetruecolor($new_width,$new_height);
// create the new image from the uploaded file
$image = imagecreatefromjpeg($_FILES["foto"]["tmp_name"]);
imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height);
// add the new path as second parameter of imagejpeg() to save the file in the specified location
imagejpeg($image_p,$fFile,100);
// the following line isn't necessary anymore
// move_uploaded_file($_FILES["foto"]["tmp_name"],".".$fFile);
$sql = "UPDATE inserzionisti SET FotoUrl ='$fFoto' where Id=$id";