Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
O pessoal como que crio um sistema de envio de arquivo em php e mysql, na net não acha nada falando só acha falando de envio de imagens e não da certo alguem me ajuda ae um tutorial alguma coisa um codigo pronto sei lá qualquer coisa que me ajude =/
>
Ué, é da mesma maneira que você envia imagens, você envia arquivo !
então aki tem akele tal de redirecionamento de imagem acaba não indo o arquivo que não é imagem tem algum tuto que fale de criar um sistema de upload que não seja pra imagem.
Cara, não quero ser grosso, mas quando você for postar aqui no fórum, evite usar 'Ajude me', 'Me Ajude', etc .. se alguém aqui for te ajudar, vai ser por vontade própria ok ? não fica forçando pra te ajudarem .. OK ?
Então, vamos lá !
O que você já tem pronto por aí ? tem como mostrar o código em que já progrediu ?
o arquivo base meu de upload tá tudo bugado, você não teria um arquivo de base ai para usar?
Não, tenho a documentação pra te passar, segue aí: http://www.php.net/manual/pt_BR/reserved.variables.files.php, http://www.php.net/manual/pt_BR/features.file-upload.post-method.php, veja os exemplos que o próprio site do PHP fornece !
Ta certo eu criei o arquivo index.php que é este:
<form enctype="multipart/form-data" action="enviar.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
e criei o arquivo enviar.php
<?php
// Nas versões do PHP anteriores a 4.1.0, deve ser usado $HTTP_POST_FILES
// ao invés de $_FILES.
$uploaddir = './musicas';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
print "O arquivo é valido e foi carregado com sucesso. Aqui esta alguma informação:\n";
print_r($_FILES); print "Possivel ataque de upload! Aqui esta alguma informação:\n";
print_r($_FILES);
}
print "</pre>";
?>
Eu tentei mais não ta enviando o arquvio para pasta o q fazer?
como faço tambem para colocar o arquivo no campo do mysql numa tabela?
Amigo, nesse tópico que você criou sobre o mesmo assunto você afirma que sabe programar em PHP, então como não sabe fazer um simples sistema de upload? Se o sistema que você tem está "bugado", por que não corrige?
Agora se você realmente desconhece a linguagem PHP continua valendo a dica que eu dei no outro tópico, estude o manual! ;)
Com uma query de inserção, esse diretório existe ? 'músicas' ? se existir, tente com './musicas/'
>
Se o sistema que você tem está "bugado", por que não corrige?
Concordo totalmente, se você tem um script com 500 linhas escritas, então ele 'buga', você refaria todo o script ?
Refazer, é sua última opção, isso quando seu código está bem mais bem porco mesmo, está totalmente inutilizável.
Opa, agora sim, você postou o código! ^_^
Observe que no seu código você está concatenando direto o nome do diretório "musicas" com o nome do arquivo, dessa forma ficaria assim: ./musicasNomeDoArquivo.ext
Coloque uma barra depois do nome do diretório, assim:
$uploaddir = './musicas/';
Se mesmo assim não funcionar, habilite as mensagens de erro e veja qual erro retorna.
EDIT:
Agora que vi que o Andrey já avisou sobre o erro. :P
tipo tava muito ruim aquele codigo segui o conselho do Leo... e fui no php.net pesquisar um pouco e achei um codigo que upa mais ele não envia nada ao banco de dados agora preciso de ajuda pra colocar ele com função no mysql tbm. a só q o sistema só ta enviando imagem não sei porque tentei já achar aonde muda o formato que up o arquivo mais nada achei veja o codigo:
<?php
/***
this is a simple and complete function and
the easyest way i have found to allow you
to add an image to a form that the user can
verify before submiting
if the user do not want this image and change
his mind he can reupload a new image and we
will delete the last
i have added the debug if !move_uploaded_file
so you can verify the result with your
directory and you can use this function to
destroy the last upload without uploading
again if you want too, just add a value...
***/
function upload_back() { global $globals;
/***
1rst set the images dir and declare a files
array we will have to loop the images
directory to write a new name for our picture
***/
$uploaddir = 'musicas/'; $dir = opendir($uploaddir);
$files = array();
/***
if we are on a form who allow to reedit the
posted vars we can save the image previously
uploaded if the previous upload was successfull.
so declare that value into a global var, we
will rewrite that value in a hidden input later
to post it again if we do not need to rewrite
the image after the new upload and just... save
the value...
***/
if(!empty($_POST['attachement_loos'])) { $globals['attachement'] = $_POST['attachement_loos']; }
/***
now verify if the file exists, just verify
if the 1rst array is not empty. else you
can do what you want, that form allows to
use a multipart form, for exemple for a
topic on a forum, and then to post an
attachement with all our other values
***/
if(isset($_FILES['attachement']) && !empty($_FILES['attachement']['name'])) {
/***
now verify the mime, i did not find
something more easy than verify the
'image/' ty^pe. if wrong tell it!
***/
if(!eregi('image/', $_FILES['attachement']['type'])) {
echo 'The uploaded file is not an image please upload a valide file!';
} else {
/***
else we must loop our upload folder to find
the last entry the count will tell us and will
be used to declare the new name of the new
image. we do not want to rewrite a previously
uploaded image
***/
while($file = readdir($dir)) { array_push($files,"$file"); echo $file; } closedir($dir);
/***
now just rewrite the name of our uploaded file
with the count and the extension, strrchr will
return us the needle for the extension
***/
$_FILES['attachement']['name'] = ceil(count($files)+'1').''.strrchr($_FILES['attachement']['name'], '.');
$uploadfile = $uploaddir . basename($_FILES['attachement']['name']);
/***
do same for the last uploaded file, just build
it if we have a previously uploaded file
***/
$previousToDestroy = empty($globals['attachement']) && !empty($_FILES['attachement']['name']) ? '' : $uploaddir . $files[ceil(count($files)-'1')];
// now verify if file was successfully uploaded
if(!move_uploaded_file($_FILES['attachement']['tmp_name'], $uploadfile)) {
echo '<pre>
Your file was not uploaded please try again
here are your debug informations:
'.print_r($_FILES) .'
</pre>';
} else {
echo 'image succesfully uploaded!';
}
/***
and reset the globals vars if we maybe want to
reedit the form: first the new image, second
delete the previous....
***/
$globals['attachement'] = $_FILES['attachement']['name'];
if(!empty($previousToDestroy)) { unlink($previousToDestroy); }
}
}
}
upload_back();
/***
now the form if you need it (with the global...):
just add the hidden input when you write your
preview script and... in the original form but!
if you have send a value to advert your script
than we are remaking the form. for exemple with a
hidden input with "reedit" as value or with a
$_GET method who can verify that condition
***/
echo '<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="attachement" name="attachement"></input>
<input type="hidden" name="attachement_loos" name="attachement_loos" value="', $globals['attachement'] ,'"></input>
<input type="submit" value="submit"></input>
</form>';
?>
Ué, é da mesma maneira que você envia imagens, você envia arquivo !