Hello everyone,
I’m quite new in php, and I admit I still have a lot to learn. With this, I’m practicing my php learning by building my website. I have this idea in mind that I would like to upload a picture. I already did the upload script and it does upload. But I’m having a problem in validation. I want to validate if the user did upload a picture. Jpeg, Jpg, and PNG is the only available file types and the size.
How can I make this. I wish I knew how to create my preview.php. Here is the snippet of my code in the user account panel. This is where the uploading happens and then redirects my uploaded file into preview.php. Any suggestions?
[code=php]<html>
<head>
<script type=”text/javascript” src=”mootools-core.js”></script>
<script type=”text/javascript”>
function stopUpload(success, name){
window.addEvent(‘domready’,function(){
$(‘photo_img’).setProperty(‘src’,”members_photo/”+name);
var photo_send = new Request({
method : ‘post’,
url : ‘update_photo.php’,
onSuccess : function(info){
if(info==”updated”){
alert(“Photo updated”);
}
}
});
var split_name = $(‘photo_img’).getProperty(‘src’).split(“/”);
var new_name = split_name[split_name.length-1];
photo_send.send(“img_src=”+new_name);
});
return true;
}
window.addEvent(‘domready’,function(){
var photo_ind = 0;
$(‘photobtn’).addEvent(‘click’,function(){
if(photo_ind == 0){
$(‘photo_upload’).setStyle(‘display’,’block’);
this.set(‘text’,’Hide Upload’);
photo_ind = 1;
}else {
$(‘photo_upload’).setStyle(‘display’,’none’);
this.set(‘html’,’Change Photo’);
photo_ind = 0;
}
});
$(‘photo_img’).setProperty(‘src’,”<?php echo $_SESSION[‘photo’]; ?>”);
});
</head>
<body>
<span id=”photobtn”>Change My Photo</span>
<div id=”photo_upload” class=”upload_form”>
<form id=”photo_form” target=”up_target” enctype=”multipart/form-data” method=”post” action=”preview.php”>
<input type=”file” name=”upload_file” id=”upload_file” />
<button type=”submit” id=”submit_btn”>Upload Photo</button>
</form>
<iframe name=”up_target” id=”up_target” style=”height:0px; width:0px; visibility:hidden; display:none; “></iframe>
</div>
</body>
</html>
This script is working. It uploads and display the photo the way I want. I wanted to add a validation, which will be performed on preview.php but I’m having a trouble on how to start it with because I’m new in input type=”file” topics. Thanks reply is much appreciated.