help wit uploading and displaying images and videos wit php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joeyxaza
Forum Newbie
Posts: 6
Joined: Mon Dec 22, 2008 2:50 am

help wit uploading and displaying images and videos wit php

Post by joeyxaza »

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
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: help wit uploading and displaying images and videos wit php

Post by watson516 »

Do you have any code yet?
User avatar
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

Post by jaoudestudios »

Google 'php upload'. Try and put something together, if you get errors let us know.
joeyxaza
Forum Newbie
Posts: 6
Joined: Mon Dec 22, 2008 2:50 am

Re: help wit uploading and displaying images and videos wit php

Post by joeyxaza »

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
User avatar
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

Post by jaoudestudios »

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.
Post Reply