help wit uploading and displaying images and videos wit php
Moderator: General Moderators
help wit uploading and displaying images and videos wit php
hi all, can anyone help me with the code on how to upload and display images and videos in php, i'm a newbie and would like to have an idea on how it is done, thanks
Re: help wit uploading and displaying images and videos wit php
Do you have any code yet?
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: help wit uploading and displaying images and videos wit php
Google 'php upload'. Try and put something together, if you get errors let us know.
Re: help wit uploading and displaying images and videos wit php
this is my current code:
<?php
define('storage','c:\\inetpub\\wwwroot\\newnfa\\images');
$conn = mysql_connect('localhost','root','jivers') or die(mysql_error());
mysql_select_db('imagetest') or die(mysql_error());
$name = $_POST['name'];
$sql = "insert into test values('$name')";
$result = mysql_query($sql) or die(mysql_error());
if(is_uploaded_file($_FILES['upload']['tmp_name']))
{
if($_FILES['upload']['type'] != "image/jpeg")
{
echo "image must be in jpeg format";
}
else
{
$result = move_uploaded_file($_FILES['upload']['tmp_name'],storage."\\$name.jpeg");
if($result == 1)
echo "success";
else
echo "failure";
}
}
?>
this is the error i get when i execute the script?
failurePHP Warning: move_uploaded_file(c:\inetpub\wwwroot\newnfa\images\xaza.jpeg) [function.move-uploaded-file]: failed to open stream: Permission denied in c:\Inetpub\wwwroot\imageload.php on line 22 PHP Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\TEMP\php63.tmp' to 'c:\inetpub\wwwroot\newnfa\images\xaza.jpeg' in c:\Inetpub\wwwroot\imageload.php on line 22
<?php
define('storage','c:\\inetpub\\wwwroot\\newnfa\\images');
$conn = mysql_connect('localhost','root','jivers') or die(mysql_error());
mysql_select_db('imagetest') or die(mysql_error());
$name = $_POST['name'];
$sql = "insert into test values('$name')";
$result = mysql_query($sql) or die(mysql_error());
if(is_uploaded_file($_FILES['upload']['tmp_name']))
{
if($_FILES['upload']['type'] != "image/jpeg")
{
echo "image must be in jpeg format";
}
else
{
$result = move_uploaded_file($_FILES['upload']['tmp_name'],storage."\\$name.jpeg");
if($result == 1)
echo "success";
else
echo "failure";
}
}
?>
this is the error i get when i execute the script?
failurePHP Warning: move_uploaded_file(c:\inetpub\wwwroot\newnfa\images\xaza.jpeg) [function.move-uploaded-file]: failed to open stream: Permission denied in c:\Inetpub\wwwroot\imageload.php on line 22 PHP Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\TEMP\php63.tmp' to 'c:\inetpub\wwwroot\newnfa\images\xaza.jpeg' in c:\Inetpub\wwwroot\imageload.php on line 22
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: help wit uploading and displaying images and videos wit php
The error states that the folder you are trying to move the image to, will not allow you to move the file in there as you do not have the relevant permissions.