-1
I am common small problem, I have a function already ready, to upload images and edit it, this function works perfectly, only it uses a library (wideimage), I would like to use another function reusing the codes only that I can not save removing the library. NOTE: it arrives to save the name in the bank, only not saved in the specified folder.
//ESSA FUNÇÃO FUNCIONA NORMAL. function uploadImagem($arquivo){ //cria um arquivo temporario, tmp = pasta temporaria, //$arquivo['name'] é recebido por parametro $img_tmp = $this->sistema_pasta_upload."tmp/".$arquivo['name'];
//pega qual é a extençãop do arquivo
$ext = strtolower(end(explode(".",$arquivo['name'])));
//verifica se é um tipo de arquivo permitido
//$this->ext_img é os arquivos permitidos.
// se não for arquivo permitido retorna "RETURN FALSE"
if(array_search($ext,$this->ext_img) === 0) {
/*passa o nome do arquivo temporario [tmp_name] e copia
* para $img_tmp
*/
if(move_uploaded_file($arquivo['tmp_name'], $img_tmp)){
// criar um nome unico e randomico para o arquivo
$foto = md5(uniqid(time())).".".$ext;
include("libs/wideimage/WideImage.php");
WideImage::load($img_tmp)->resize(614, 299)->saveToFile($this->sistema_pasta_upload.$foto);
WideImage::load($img_tmp)->crop('center', 'center', 257, 247)->saveToFile($this->sistema_pasta_upload."thumb/".$foto);
//deleta o arquivo temporario
unlink($this->sistema_pasta_upload."tmp/".$arquivo['name']);
//retorna nome do arquivo para salvar no banco
return $foto;
}
}
return false;
}
/*THIS FUNCTION CAN BE SAVED TO NORMAL FOLDER TMP ONLY THEN NOT SAVED IN THUMB FOLDER AFTER RECEIVING MD5. */
Function uploadArchive($arq_name){ //creates a temporary file, tmp = temporary folder, //$arq_name['name'] is received by parameter $arq_tmp = $this->sistema_pasta_upload." tmp/". $arq_name['name'];
//pega qual é a extençãop do arquivo
$ext = strtolower(end(explode(".",$arq_nome['name'])));
//verifica se é um tipo de arquivo permitido
//$this->ext_img é os arquivos permitidos.
// se não for arquivo permitido retorna "RETURN FALSE"
if(array_search($ext,$this->ext_img) === 0) {
/*passa o nome do arquivo temporario [tmp_name] e copia
* para $arq_tmp
*/
if(move_uploaded_file($arq_nome['tmp_name'], $arq_tmp)){
// criar um nome unico e randomico para o arquivo
$foto = md5(uniqid(time())).".".$ext;
//preciso salvar o arquivo apartir daqui.
move_uploaded_file($foto,"thumb/");
//deleta o arquivo temporario
//unlink($this->sistema_pasta_upload."tmp/".$arq_nome['name']);
//retorna nome do arquivo para salvar no banco
return $foto;
}
}
return false;
}
then the problem is to leave the name with the MD5 not to repeat names, so will not exit the MD5
– will
(md5($arquivo['tmp_name'])
Function above transforms the file name into md5. You can add time too, it’s efficient, just put this code: time() without parameters and arguments.– Julio Mac
Warning: move_uploaded_file() expects Exactly 2 Parameters, 1 Given in C: xampp htdocs intranet intra application.php on line 122 of this error
– will
I think it might be in my container something, I’ll check.
– will
It didn’t work, this complicated.
– will
@will realize that he uses 2 meters there in the answer, you used only 1 and so got this Warning. would be: move_uploaded_file(md5($file['tmp_name']), $img_tmp)
– Jhonny Mesquita
Well, I would like to know why I voted no. topic stayed here 2 days, and the man who voted against did not come here to help, I found the solution and I thank those who tried to help and posted as a response and now the almighty and perfect god of programming comes to vote negative? Have pity also some people here also saw...
– will