Jump to content


Photo

An issue with renam I think... [Solved]


  • Please log in to reply
4 replies to this topic

#1 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 19 July 2006 - 03:53 AM

Im in the begining stages of writing an upload script. i want the results page (below) to show the image. Everything seems ok but the image comes out broken and as <img src="/art/1">. 1!!! what? Here is my code.

<?php

if($_GET[action]=="art") 
{

$target_path = "art/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

//Rename the file
$artnama = basename( $_FILES['uploadedfile']['name']);
$artdir = 'art/';
$randomnum = md5(mktime());

$newfilename = rename("$artdir$artnama", "$artdir$randomnum$artnama");

echo 'Your art has been up loaded! <br /> <img src="/art/' . $newfilename . '">';



} else{
    echo "There was an error uploading the file, please try again!";
} 
} 
?>


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 July 2006 - 03:58 AM

try that ok
<?php

if($_GET[action]=="art") 
{

$target_path = "art/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

//Rename the file
$artnama = basename( $_FILES['uploadedfile']['name']);
$artdir = 'art/';
$randomnum = md5(mktime());

$newfilename = rename("$artdir$artnama", "$artdir$randomnum$artnama");

echo "Your art has been up loaded! <br /> <img src= '$target_path . $newfilename '>";



} else{
    echo "There was an error uploading the file, please try again!";
} 
} 
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 19 July 2006 - 04:08 AM

No that didnt help it made the img src=%20.%201 . I wonder if Im even allowed to do
$newfilename = rename("$artdir$artnama", "$artdir$randomnum$artnama");
? It makes since but all the examples I've seen never does this.

#4 foreverhex

foreverhex
  • Members
  • PipPipPip
  • Advanced Member
  • 91 posts

Posted 19 July 2006 - 04:31 AM

I had to switch the $newfilename around.
<?php

if($_GET[action]=="art") 
{

$target_path = "art/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

//Rename the file
$artnama = basename( $_FILES['uploadedfile']['name']);
$artdir = 'art/';
$randomnum = md5(mktime());
rename("$artdir$artnama", "$artdir$randomnum$artnama");

$newfilename = $artdir . $randomnum . $artnama;

echo 'Your art has been up loaded! <br /> <img src="' . $newfilename . '">';


} else{
    echo 'There was an error uploading the file, please try again!';
} 
} 
?>
Doesnt seem smart but it works.

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 July 2006 - 04:34 AM

well done!

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users