copy() question ( 3 Views )
-
hey, I am developing a CMS. on one page i need to be able to add articles with date author status i also want to be able to choose a file to copy to another directory. then in my db the file path gets inserted into my db. I have it coded but it just wonr work. Im on a mac OSX, i changed the permissions to 777 on the folder that will store those images. Here is the code:
PHP Code:
<?php
session_start();
include("general_functions.php");
include("error_functions.php");
html_header("global3","Uncommon Grounds Article Options");
$belong_here = test_login();
if(!$belong_here)
{
die("<p>" . custom_error(2,"You are not logged in") . "</p> \n <p><a href='index.php'>Log in</a></p>");
}
else
{
if(isset($_POST['submit']))
{
$author = $_POST['author'];
$date = $_REQUEST['date'];
$status = $_REQUEST['status'];
$article = $_REQUEST['article'];
/*$image_upload = upload_title_image();*/
$file_to_copy = $_FILES['uploadImage']['tmp_name'];
$new_file_name = time() . $img_ext;
$file_dir = '/images/UGrounds CMS/' . $new_file_name;
if(is_uploaded_file($file_to_copy))
{
if(!copy($file_to_copy,$file_dir))
{
die("<p>sorry</p>");
}
}
echo("<p>Image add successfully</p>");
$article_status = add_article($article,$author,$status,$date,$img_location,$img_ext);
if($article_status)
{
echo("<p>Article Added successfully</p>");
}
else
{
echo("<p>" . sql_error(3,"Error add article to database, please try again") . "</p>");
}
}
else
{
display_article_form();
html_footer();
}
}
?>
its a pretty simple script but it wont work. Take a look if you know a solution please let me know.
uploadImage - is the name of the form field on the page that calls this script.
(vzss, Mongolia)
i tried it with a couple other images and i get the same result.
(Buğra, Cook Islands)
Maybe it's the wrong extention, so the file is being read incorrectly.
(gürkan, Malta)
I assume you mean recording them into a DB or something. Im not recording them yet. Im just making sure it works cause ive had a problem with this for a while. It does put a file in the /Library/WebServer/Documents/images/UGrounds CMS/ but when i go that that directory and double click on the icon nothing comes up. I tried opening it with camino but nothing came up.
(___ümit___, Angola)
Sure you have the right url, because your not printing or recording the images url anywhere?
(reyhan , Saint Pierre and Miquelon)
OK wait, it puts a file in that directory that i specify but when i click on the file to look at it i get an error message in camino:
The file /Library/WebServer/Documents/images/UGrounds%20CMS/1066088867.gif cannot be found. Please check the location and try again.
if you got any other ideas i appreciate it.
(melis , Botswana)
O, thank you so much for your help. I got it
here is the code that works now:
PHP Code:
<?php
session_start();
include("general_functions.php");
include("error_functions.php");
html_header("global3","Uncommon Grounds Article Options");
$belong_here = test_login();
if(!$belong_here)
{
die("<p>" . custom_error(2,"You are not logged in") . "</p> \n <p><a href='index.php'>Log in</a></p>");
}
else
{
if(isset($_POST['submit']))
{
$author = $_POST['author'];
$date = $_REQUEST['date'];
$status = $_REQUEST['status'];
$article = $_REQUEST['article'];
$img_ext = $_REQUEST['extension'];
$new_file_name = time() . $img_ext;
if(is_uploaded_file($_FILES['uploadImage']['tmp_name']))
{
echo("<p>uploaded</p>");
if(!move_uploaded_file($_FILES['uploadImage']['tmp_name'],"/Library/WebServer/Documents/images/UGrounds CMS/" . $new_file_name))
{
echo($_FILES['uploadImage']['error']);
die("<p>sorry not moved</p>");
}
}
else
{
die("<p>sorry not uploaded</p>");
}
echo("<p>Image added successfully</p>");
$article_status = add_article($article,$author,$status,$date,$img_location,$img_ext);
if($article_status)
{
echo("<p>Article Added successfully</p>");
}
else
{
echo("<p>" . sql_error(3,"Error add article to database, please try again") . "</p>");
}
}
else
{
display_article_form();
html_footer();
}
}
?>
(inci, Colombia)
$_FILES['uploadImage']['type'] holds the image extention, your adding the image extention twice in the move_uploaded_file() function, that's your problem.
Change this:
PHP Code:
!move_uploaded_file($_FILES['uploadImage']['tmp_name'],"/images/UGrounds CMS/" . $new_file_name . "." . $_FILES['uploadImage']['type'])
...into this:
PHP Code:
!move_uploaded_file($_FILES['uploadImage']['tmp_name'],"/images/UGrounds CMS/" . $new_file_name)
(nisa, Hungary)
i tried that new way of uploading the image. It still wont work
heres the new code:
PHP Code:
<?php
session_start();
include("general_functions.php");
include("error_functions.php");
html_header("global3","Uncommon Grounds Article Options");
$belong_here = test_login();
if(!$belong_here)
{
die("<p>" . custom_error(2,"You are not logged in") . "</p> \n <p><a href='index.php'>Log in</a></p>");
}
else
{
if(isset($_POST['submit']))
{
$author = $_POST['author'];
$date = $_REQUEST['date'];
$status = $_REQUEST['status'];
$article = $_REQUEST['article'];
$new_file_name = time() . $img_ext;
if(is_uploaded_file($_FILES['uploadImage']['tmp_name']))
{
echo("uploaded");
if(!move_uploaded_file($_FILES['uploadImage']['tmp_name'],"/images/UGrounds CMS/" . $new_file_name . "." . $_FILES['uploadImage']['type']))
{
die("<p>sorry not moved</p>");
}
}
else
{
die("<p>sorry not uploaded</p>");
}
echo("<p>Image add successfully</p>");
$article_status = add_article($article,$author,$status,$date,$img_location,$img_ext);
if($article_status)
{
echo("<p>Article Added successfully</p>");
}
else
{
echo("<p>" . sql_error(3,"Error add article to database, please try again") . "</p>");
}
}
else
{
display_article_form();
html_footer();
}
}
?>
I put a couple of tests in there to see what is not working. It appears the file is getting uploaded (echo("uploaded");). but when it tests to see if the file was moved it isnt moved (die("<p>Sorry not moved</p>");).
Im wondering if i have to change the group that, that folder belongs to or the owner. I set the permission on that directory to 777 so i wouldnt think i would have to. but im not sure. Im on a mac OSX.
(murat, Taiwan, Province of China)
Don't use copy, it's confusing and tends to spit out errors for no reasons I can see. Use move_uploaded_file(); much, much better. You can use it like this:
PHP Code:
move_uploaded_file($_FILES['uploadImage']['tmp_name'], "images/" . $name . "." . $_FILES['uploadImage']['type']);
(SELAHATTİN, New Caledonia)
Yes, but where are you getting the image extention from?
(ünal, Luxembourg)
Related Topics ... (or search in 1.720.883 topics !)
portfolio question. hard copy vs digital copy??? (2) old vhs, copy of a copy of a copy, and so on, and color smearing (4) ot: question on basic copy (5) instant copy question (2) web sales copy question (11) dvd instant copy question (1) dvd copy legality question (6) weird copy question/or help with robocopy (4) file copy question, it's tricky :) (2)
copyright © 2007-2031 Pfodere.COM ( 5 Pfoyihuee Online )
|