/    Sign up×
Community /Pin to ProfileBookmark

im lost in my own script…

alright, let me see if i can try to explain this to you…i have a script that saves image URL’s and ID’s in a database as they are uploaded to the server…that part is working fine…however, i also want to give users the ability to rename and delete files on the server…ill just post the rename part here for now, ill work on the delete part later, lol…heres what i have so far:

[code=php]for($i = 0; $i <= $num; $i++){

if(!empty($edit[$i])){
$ids[$i] = $edit[$i];
}

$query = mysql_query(
“SELECT ID, imageurl, size FROM imagelist WHERE ID = ‘”.$ids[$i].”‘”
);

while($row = mysql_fetch_array($query)){

$size = explode(“.”, ($row[‘size’]/1000));
$size = $size[0];

$name_ext = explode(“.”, $row[‘imageurl’]);

$contents .= ” <tr>
<input type=”hidden” name=”file[]” value=””.$row[‘imageurl’].”” />
<td>
<input type=”text” name=”rename[]” value=””.$name_ext[0].”” size=”15″ />.”.$name_ext[1].”
</td>
<td>
$size Kb
</td>
<td>
<input type=”checkbox” name=”delete[]” value=””.$row[‘ID’].”” />
</td>
</tr>
“;

}

}[/code]

once submitted (the button is down lower), the variables are sent through this script, which [i]should[/i] check the database to see if any names have been changed, and then rename them if they have been…

[code=php]for($i = 0; $i <= $num; $i++){

$filename = explode(“.”, $_POST[‘file’][$i]);
$filen = $filename[0];

if($_POST[‘rename’][$i] != $filen){

$query = mysql_query(
“SELECT ID, user, imageurl FROM imagelist WHERE ID = ‘”.$id[$i].”‘”
);
while($row = mysql_fetch_array($query)){

rename($row[‘user’].”/”.$row[‘imageurl’], $row[‘user’].”/”.$_POST[‘rename’][$i].$filename[1]) or die(“Couldn’t rename “.$_POST[‘file’][$i]);

$sql = mysql_query(
“UPDATE imagelist SET imageurl = ‘”.$_POST[‘rename’][$i].$filename[1].”‘, date = CURDATE() WHERE ID = ‘”.$id[$i].”‘”
);

if(!$sql){
die(“Couldn’t rename “.$_POST[‘file’][$i].” in the database: “.mysql_error());
}

}

}

mysql_free_result($sql);

}[/code]

the only problem is that it doesnt seem to be receiving the variables, either that or the script just doesnt work…sorry for throwing a ton of script at ya, but ask if you need any clarification…thanx?

[b]P.S.:[/b] would it be easier to just attach the whole file?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Da_WarriahauthorAug 29.2003 — hmm...looks like i scared everyone away...?

ill try breaking down the script, see if i can work it together piece by piece...?
×

Success!

Help @Da_Warriah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...